/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "powermanager.h"
#include "robotmanager.h"
#include "messagelog.h"
#include "globalmanager.h"
#include <qmessagebox.h>
#include "robotcontrol.h"
#include "filebackupmanagedlg.h"
#include <QDebug>
#include "ethercatVendorId.h"
#include <qfiledialog.h>
#include "fleetservice.h"
#include "../ProgramEngine/programengine.h"
#include "robotengine.h"
#include "mccontrollerthread.h"

extern RobotControl* robCtl;
extern FleetService *fleetService;

MainWindow::MainWindow(PowerManager *p_powerMangerIn,QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
//    ui->lineEdit->setFocus();
//    setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
    timerTickCount=0;
    userInfo.account =ENUM_POWER_ADMIN;
    p_powerManger = p_powerMangerIn;
    choose_axis =0;
    robotId = 0;
    pos=0;
    messageSize=0;
    servoOnState=false;
    jogOnFlag=false;
    debugFlag=0;
    // PowerManager *p_powerManger;

    dir=false;
//    timer2=new QTimer();
//    connect( timer2, SIGNAL(timeout()), this, SLOT(move_slot()) );

    timer=new QTimer();
    connect( timer, SIGNAL(timeout()), this, SLOT(timeOut_slot()) );
    timer->start( 500 );

    filebackDlg=new FileBackupManageDlg(p_powerManger,userInfo);
    filebackDlg->hide();

    //initial
    model_taskInfo = new QStandardItemModel();
    QStringList labels0 = QObject::trUtf8("变量,value,-").simplified().split(",");
    model_taskInfo->setHorizontalHeaderLabels(labels0);
    ui->tableView_taskInfo->setColumnWidth(1,120);

    model_progremEngine = new QStandardItemModel();
    QStringList labels = QObject::trUtf8("变量,value,-").simplified().split(",");
    model_progremEngine->setHorizontalHeaderLabels(labels);
    ui->tableView_programEngine->setColumnWidth(1,120);

    model_motionEngine = new QStandardItemModel();
    QStringList labels2 = QObject::trUtf8("变量,value,-").simplified().split(",");
    model_motionEngine->setHorizontalHeaderLabels(labels2);
    ui->tableView_motionEngine->setColumnWidth(1,120);

    model_ethercatSlavesInfo = new QStandardItemModel();
    QStringList labels3 = QObject::trUtf8("变量,value,-").simplified().split(",");
    model_ethercatSlavesInfo->setHorizontalHeaderLabels(labels3);
    ui->tableView_ethercatSlavesInfo->setColumnWidth(1,120);

    model_axisgroupCalibrateInfo = new QStandardItemModel();
    QStringList labels4 = QObject::trUtf8("变量,value,-").simplified().split(",");
    model_axisgroupCalibrateInfo->setHorizontalHeaderLabels(labels4);
    ui->tableView_axisgroupCalibrateInfo->setColumnWidth(1,120);

    model_ecatDebugInfo = new QStandardItemModel();
    QStringList labels5 = QObject::trUtf8("变量,value,-").simplified().split(",");
    model_axisgroupCalibrateInfo->setHorizontalHeaderLabels(labels5);
    ui->tableView_ethercatDebugInfo->setColumnWidth(1,120);

    model_batteryInfo = new QStandardItemModel();
    QStringList labels6 = QObject::trUtf8("变量,value,-").simplified().split(",");
    model_batteryInfo->setHorizontalHeaderLabels(labels6);
    ui->tableView_batteryInfo->setColumnWidth(1,120);

    model_virtualLineControl = new QStandardItemModel();
    QStringList labels7 = QObject::trUtf8("变量,value,-").simplified().split(",");
    model_virtualLineControl->setHorizontalHeaderLabels(labels7);
    ui->tableView_virtualLineControl->setColumnWidth(1,120);


    model_poindCloudSafeInfo = new QStandardItemModel();
    model_canDebugInfo = new QStandardItemModel();
    model_modbusDebugInfo = new QStandardItemModel();
    model_fleetDebugInfo = new QStandardItemModel();

}

MainWindow::~MainWindow()
{
    if(NULL!=ui)
    {
        delete ui;
        ui = NULL;
    }
}

int MainWindow::showMotionForm()
{
    return p_powerManger->showMotionForm(ui->comboBox_robotId->currentIndex()+1);
}

int MainWindow::setDebugFlag(int debugFlagIn)
{
    debugFlag=debugFlagIn;
    return 1;
}

int MainWindow::setMainVersion(string versionIn, string dateIn)
{
    QString info="主版本:";
    info+=QString::fromStdString(versionIn)+" "+QString::fromStdString(dateIn);
    ui->mainVersionInfo->setText(info);
    return 1;
}

void MainWindow::showPoitionInfo(UpdateDataLv2 &updateDataLv2)
{

    updateDataLv2.currentPositionJoint.positionValue.resize(12);
    ui->lineEdit_J1->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[0],'f',2));
    ui->lineEdit_J2->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[1],'f',2));
    ui->lineEdit_J3->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[2],'f',2));
    ui->lineEdit_J4->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[3],'f',2));
    ui->lineEdit_J5->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[4],'f',2));
    ui->lineEdit_J6->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[5],'f',2));
    ui->lineEdit_J7->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[6],'f',2));
    ui->lineEdit_J8->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[7],'f',2));
    ui->lineEdit_J9->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[8],'f',2));
    ui->lineEdit_J10->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[9],'f',2));
    ui->lineEdit_J11->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[10],'f',2));
    ui->lineEdit_J12->setText(QString::number(updateDataLv2.currentPositionJoint.positionValue[11],'f',2));

    updateDataLv2.currentPositionWorld.positionValue.resize(6);
    ui->lineEdit_X->setText(QString::number(updateDataLv2.currentPositionWorld.positionValue[0],'f',2));
    ui->lineEdit_Y->setText(QString::number(updateDataLv2.currentPositionWorld.positionValue[1],'f',2));
    ui->lineEdit_Z->setText(QString::number(updateDataLv2.currentPositionWorld.positionValue[2],'f',2));
    ui->lineEdit_W->setText(QString::number(updateDataLv2.currentPositionWorld.positionValue[3],'f',2));
    ui->lineEdit_P->setText(QString::number(updateDataLv2.currentPositionWorld.positionValue[4],'f',2));
    ui->lineEdit_R->setText(QString::number(updateDataLv2.currentPositionWorld.positionValue[5],'f',2));

}

void MainWindow::showProgramRunningInfo(UpdateDataLv2 &updateDataLv2)
{
    RobotEngine*rob=p_powerManger->robotManager->robotsMap.value( robotId, NULL );
    if(NULL==rob)
    {
        return;
    }
    if(0<updateDataLv2.currentRunFile.runingFileName.size())
    {
        ui->lineEdit_run_file_name->setText(QString::fromStdString(updateDataLv2.currentRunFile.runingFileName[0]));
        if(oldRuningProgramName!=updateDataLv2.currentRunFile.runingFileName[0])
        {
            ui->listWidget->clear();
            QVector<QString> listStrOut;
            rob->programEngine->getCmdStrList(listStrOut);
            ui->listWidget->addItems(  listStrOut.toList() );
            oldRuningProgramName=updateDataLv2.currentRunFile.runingFileName[0];
        }
    }

    if( updateDataLv2.currentRunFile.runningFileLine.size()>0 )
    {
           int line=updateDataLv2.currentRunFile.runningFileLine[0] ;
           ui->lineEdit_line->setText(QString::number(line+1) );
           ui->listWidget->setCurrentRow( line );

           //other
            if( ui->comboBox_runMode->currentIndex()!=rob->programEngine->getRunModel() )
            {
                ui->comboBox_runMode->setCurrentIndex( rob->programEngine->getRunModel() ) ;
            }
            if( ui->comboBox_moveType->currentIndex()!=rob->programEngine->getMoveType() )
            {
                ui->comboBox_moveType->setCurrentIndex(  rob->programEngine->getMoveType() );

            }

            ui->label_manual_speed->setText(  "手动速率" + QString::number(updateDataLv2.globalManSpeed) +"%" );
            ui->label_auto_speed->setText( "自动速率" + QString::number( updateDataLv2.globalProSpeed) +"%"  );
    }
}

void MainWindow::showDebugInfo_motionServer(MotionDebugInfo info)
{
    model_motionEngine->clear();
    //定义item
    QStandardItem* item = 0;

    item = new QStandardItem("deltaTime");
    model_motionEngine->setItem(0,0,item);
    item = new QStandardItem(QString("%1").arg(info.deltaTime));
    model_motionEngine->setItem(0,1,item);

    item = new QStandardItem("CLineRemainTime");
    model_motionEngine->setItem(1,0,item);
    item = new QStandardItem(QString::number(info.currentLineRemainingTime,'f',3));
    model_motionEngine->setItem(1,1,item);

    item = new QStandardItem("CLine");
    model_motionEngine->setItem(2,0,item);
    item = new QStandardItem(QString::number(info.currentLine,'f',3));
    model_motionEngine->setItem(2,1,item);

    item = new QStandardItem("lineQueueSize");
    model_motionEngine->setItem(3,0,item);
    item = new QStandardItem(QString("%1").arg(info.lineQueueSize));
    model_motionEngine->setItem(3,1,item);

    item = new QStandardItem("ServerMode");
    model_motionEngine->setItem(4,0,item);
    item = new QStandardItem(QString("%1").arg(info.motionServerMode));
    model_motionEngine->setItem(4,1,item);

    item = new QStandardItem("Status");
    model_motionEngine->setItem(5,0,item);
    item = new QStandardItem(QString("%1").arg(info.basicStatus));
    model_motionEngine->setItem(5,1,item);

    item = new QStandardItem("commandQueueSize");
    model_motionEngine->setItem(6,0,item);
    item = new QStandardItem(QString("%1").arg(info.commandQueueSize));
    model_motionEngine->setItem(6,1,item);

    item = new QStandardItem("isVelpEmpty");
    model_motionEngine->setItem(7,0,item);
    item = new QStandardItem(QString("%1").arg(info.isVelprofileEmpty));
    model_motionEngine->setItem(7,1,item);

    item = new QStandardItem("timeAxisScale0");
    model_motionEngine->setItem(8,0,item);
    item = new QStandardItem(QString::number(info.timeAxisScale0,'f',3));
    model_motionEngine->setItem(8,1,item);

    item = new QStandardItem("commonThrdStage");
    model_motionEngine->setItem(9,0,item);
    item = new QStandardItem(QString("%1").arg(info.commonThreadStage));
    model_motionEngine->setItem(9,1,item);

    item = new QStandardItem("realThrdStage");
    model_motionEngine->setItem(10,0,item);
    item = new QStandardItem(QString("%1").arg(info.realThreadStage));
    model_motionEngine->setItem(10,1,item);

    item = new QStandardItem("threadId");
    model_motionEngine->setItem(11,0,item);
    item = new QStandardItem(QString("%1").arg(info.threadId));
    model_motionEngine->setItem(11,1,item);

    item = new QStandardItem("AXISG_stage");
    model_motionEngine->setItem(12,0,item);
    item = new QStandardItem(QString("%1").arg(info.axisGroupInfo.stage));
    model_motionEngine->setItem(12,1,item);

    item = new QStandardItem("AXISG_dTime");
    model_motionEngine->setItem(13,0,item);
    item = new QStandardItem(QString("%1").arg(info.axisGroupInfo.deltaTime));
    model_motionEngine->setItem(13,1,item);

    ui->tableView_motionEngine->setModel(model_motionEngine);
    ui->tableView_motionEngine->resizeColumnToContents(0);
    ui->tableView_motionEngine->resizeColumnToContents(1);
    ui->tableView_motionEngine->resizeColumnToContents(2);
    ui->tableView_motionEngine->show();


}

void MainWindow::showDebugInfo_virtualLineControl(VirtualLineDebugInfo info)
{
    model_virtualLineControl->clear();
    //定义item
    QStandardItem* item = 0;

    item = new QStandardItem("calculateBiasType");
    model_virtualLineControl->setItem(0,0,item);
    item = new QStandardItem(QString("%1").arg(info.calculateBiasType));
    model_virtualLineControl->setItem(0,1,item);

    item = new QStandardItem("CLineRemainTime");
    model_virtualLineControl->setItem(1,0,item);
    item = new QStandardItem(QString::number(info.currentLineRemainingTime,'f',3));
    model_virtualLineControl->setItem(1,1,item);

    item = new QStandardItem("CLine");
    model_virtualLineControl->setItem(2,0,item);
    item = new QStandardItem(QString::number(info.currentLine,'f',3));
    model_virtualLineControl->setItem(2,1,item);

    item = new QStandardItem("lineQueueSize");
    model_virtualLineControl->setItem(3,0,item);
    item = new QStandardItem(QString("%1").arg(info.lineQueueSize));
    model_virtualLineControl->setItem(3,1,item);

    item = new QStandardItem("barrierProtectRatio");
    model_virtualLineControl->setItem(4,0,item);
    item = new QStandardItem(QString::number(info.barrierProtectRatio,'f',3));
    model_virtualLineControl->setItem(4,1,item);

    item = new QStandardItem("Status");
    model_virtualLineControl->setItem(5,0,item);
    item = new QStandardItem(QString("%1").arg(info.basicStatus));
    model_virtualLineControl->setItem(5,1,item);

    item = new QStandardItem("commandQueueSize");
    model_virtualLineControl->setItem(6,0,item);
    item = new QStandardItem(QString("%1").arg(info.commandQueueSize));
    model_virtualLineControl->setItem(6,1,item);

    item = new QStandardItem("isVelpEmpty");
    model_virtualLineControl->setItem(7,0,item);
    item = new QStandardItem(QString("%1").arg(info.isVelprofileEmpty));
    model_virtualLineControl->setItem(7,1,item);

    item = new QStandardItem("timeAxisScale0");
    model_virtualLineControl->setItem(8,0,item);
    item = new QStandardItem(QString::number(info.timeAxisScale0,'f',3));
    model_virtualLineControl->setItem(8,1,item);

    item = new QStandardItem("commonThrdStage");
    model_virtualLineControl->setItem(9,0,item);
    item = new QStandardItem(QString("%1").arg(info.commonThreadStage));
    model_virtualLineControl->setItem(9,1,item);

    item = new QStandardItem("realThrdStage");
    model_virtualLineControl->setItem(10,0,item);
    item = new QStandardItem(QString("%1").arg(info.realThreadStage));
    model_virtualLineControl->setItem(10,1,item);

    item = new QStandardItem("threadId");
    model_virtualLineControl->setItem(11,0,item);
    item = new QStandardItem(QString("%1").arg(info.threadId));
    model_virtualLineControl->setItem(11,1,item);

    item = new QStandardItem("AXISG_stage");
    model_virtualLineControl->setItem(12,0,item);
    item = new QStandardItem(QString("%1").arg(info.axisGroupInfo.stage));
    model_virtualLineControl->setItem(12,1,item);

    item = new QStandardItem("AXISG_dTime");
    model_virtualLineControl->setItem(13,0,item);
    item = new QStandardItem(QString("%1").arg(info.axisGroupInfo.deltaTime));
    model_virtualLineControl->setItem(13,1,item);

    item = new QStandardItem("deltaDistance");
    model_virtualLineControl->setItem(14,0,item);
    item = new QStandardItem(QString::number(info.deltaDistance,'f',3));
    model_virtualLineControl->setItem(14,1,item);

    item = new QStandardItem("deltaAngle");
    model_virtualLineControl->setItem(15,0,item);
    item = new QStandardItem(QString::number(info.deltaAngle,'f',3));
    model_virtualLineControl->setItem(15,1,item);

    item = new QStandardItem("absoluteDistance");
    model_virtualLineControl->setItem(16,0,item);
    item = new QStandardItem(QString::number(info.absoluteDistance,'f',3));
    model_virtualLineControl->setItem(16,1,item);

    item = new QStandardItem("absoluteAngle");
    model_virtualLineControl->setItem(17,0,item);
    item = new QStandardItem(QString::number(info.absoluteAngle,'f',3));
    model_virtualLineControl->setItem(17,1,item);

    item = new QStandardItem("deltaTime");
    model_virtualLineControl->setItem(18,0,item);
    item = new QStandardItem(QString::number(info.deltaTime));
    model_virtualLineControl->setItem(18,1,item);


    item = new QStandardItem("ServerMode");
    model_virtualLineControl->setItem(19,0,item);
    item = new QStandardItem(QString("%1").arg(info.motionServerMode));
    model_virtualLineControl->setItem(19,1,item);

    ui->tableView_virtualLineControl->setModel(model_virtualLineControl);
    ui->tableView_virtualLineControl->resizeColumnToContents(0);
    ui->tableView_virtualLineControl->resizeColumnToContents(1);
    ui->tableView_virtualLineControl->resizeColumnToContents(2);
    ui->tableView_virtualLineControl->show();
}

void MainWindow::showDebugInfo_taskInfo(TaskManagerInfo taskInfo)
{
    model_taskInfo->clear();
    //定义item
    QStandardItem* item = 0;

    int lineSize=10;

    for(int i=0;i<taskInfo.runningLine.size();i++)
    {
        item = new QStandardItem("任务号");
        model_taskInfo->setItem(lineSize*i+0,0,item);
        item = new QStandardItem(QString::number(taskInfo.taskIndex[i]));
        model_taskInfo->setItem(lineSize*i+0,1,item);

        item = new QStandardItem("fileName");
        model_taskInfo->setItem(lineSize*i+1,0,item);
        item = new QStandardItem(QString("%1").arg(
                                     QString::fromStdString(taskInfo.fileName[i])));
        model_taskInfo->setItem(lineSize*i+1,1,item);

        item = new QStandardItem("runningLine");
        model_taskInfo->setItem(lineSize*i+2,0,item);
        item = new QStandardItem(QString::number(taskInfo.runningLine[i],'f',3));
        model_taskInfo->setItem(lineSize*i+2,1,item);

        item = new QStandardItem("runningThreadId");
        model_taskInfo->setItem(lineSize*i+3,0,item);
        QString tmpStr;
        tmpStr.sprintf("%x",taskInfo.runningThreadId[i]);
        item = new QStandardItem(tmpStr);
        model_taskInfo->setItem(lineSize*i+3,1,item);

        item = new QStandardItem("taskThreadIsRunning");
        model_taskInfo->setItem(lineSize*i+4,0,item);
        item = new QStandardItem(QString("%1").arg(taskInfo.taskThreadIsRunning[i]));
        model_taskInfo->setItem(lineSize*i+4,1,item);

        item = new QStandardItem("taskThreadIsFinished");
        model_taskInfo->setItem(lineSize*i+5,0,item);
        item = new QStandardItem(QString("%1").arg(taskInfo.taskThreadIsFinished[i]));
        model_taskInfo->setItem(lineSize*i+5,1,item);

        item = new QStandardItem("isRunState");
        model_taskInfo->setItem(lineSize*i+6,0,item);
        item = new QStandardItem(QString("%1").arg(taskInfo.state[i]));
        model_taskInfo->setItem(lineSize*i+6,1,item);

        item = new QStandardItem("isInLoop");
        model_taskInfo->setItem(lineSize*i+7,0,item);
        item = new QStandardItem(QString("%1").arg(taskInfo.isInLoop[i]));
        model_taskInfo->setItem(lineSize*i+7,1,item);


    }
    ui->tableView_taskInfo->setModel(model_taskInfo);
    ui->tableView_taskInfo->resizeColumnToContents(0);
    ui->tableView_taskInfo->resizeColumnToContents(1);
    ui->tableView_taskInfo->resizeColumnToContents(2);
    ui->tableView_taskInfo->show();
}

void MainWindow::showDebugInfo_programEngine(std::vector<ProgramEngineDebugInfo> infoList)
{
    model_progremEngine->clear();
    //定义item
    QStandardItem* item = 0;

    int lineSize=10;

    for(int i=0;i<infoList.size();i++)
    {
        item = new QStandardItem("任务号");
        model_progremEngine->setItem(lineSize*i+0,0,item);
        item = new QStandardItem(QString("%1######").arg(i));
        model_progremEngine->setItem(lineSize*i+0,1,item);

        item = new QStandardItem("progId_current");
        model_progremEngine->setItem(lineSize*i+1,0,item);
        item = new QStandardItem(QString("%1").arg(infoList[i].programIndex_currentRunning));
        model_progremEngine->setItem(lineSize*i+1,1,item);

        item = new QStandardItem("progCountNumber");
        model_progremEngine->setItem(lineSize*i+2,0,item);
        item = new QStandardItem(QString("%1").arg(infoList[i].programCountNum));
        model_progremEngine->setItem(lineSize*i+2,1,item);

        item = new QStandardItem("runningLine");
        model_progremEngine->setItem(lineSize*i+3,0,item);
        item = new QStandardItem(QString::number(infoList[i].runningLineFloat,'f',3));
        model_progremEngine->setItem(lineSize*i+3,1,item);

        item = new QStandardItem("progInstrucType");
        model_progremEngine->setItem(lineSize*i+4,0,item);
        item = new QStandardItem(QString("%1").arg(infoList[i].programInstructionType));
        model_progremEngine->setItem(lineSize*i+4,1,item);

        item = new QStandardItem("progEngineStatus");
        model_progremEngine->setItem(lineSize*i+5,0,item);
        item = new QStandardItem(QString("%1").arg(infoList[i].engineStatus));
        model_progremEngine->setItem(lineSize*i+5,1,item);

        item = new QStandardItem("运动指令Stage");
        model_progremEngine->setItem(lineSize*i+6,0,item);
        item = new QStandardItem(QString("%1").arg(infoList[i].motionStage));
        model_progremEngine->setItem(lineSize*i+6,1,item);

        item = new QStandardItem("最后加行号");
        model_progremEngine->setItem(lineSize*i+7,0,item);
        item = new QStandardItem(QString("%1").arg(infoList[i].motionInstrutionAdd));
        model_progremEngine->setItem(lineSize*i+7,1,item);

        item = new QStandardItem("引擎_STAGE");
        model_progremEngine->setItem(lineSize*i+8,0,item);
        item = new QStandardItem(QString("%1").arg(infoList[i].stage));
        model_progremEngine->setItem(lineSize*i+8,1,item);
    }
    ui->tableView_programEngine->setModel(model_progremEngine);
    ui->tableView_programEngine->resizeColumnToContents(0);
    ui->tableView_programEngine->resizeColumnToContents(1);
    ui->tableView_programEngine->resizeColumnToContents(2);
    ui->tableView_programEngine->show();

}

void MainWindow::showDebugInfo_ethercat(EthercatDebugInfo info)
{
    model_ecatDebugInfo->clear();
    //定义item
    QStandardItem* item = 0;

    item = new QStandardItem("MsCommandState");
    model_ecatDebugInfo->setItem(0,0,item);
    item = new QStandardItem(QString("%1").arg(info.masterCommandState));
    model_ecatDebugInfo->setItem(0,1,item);

    item = new QStandardItem("MsCurrentState");
    model_ecatDebugInfo->setItem(1,0,item);
    item = new QStandardItem(QString("%1").arg(info.masterCurrentState));
    model_ecatDebugInfo->setItem(1,1,item);

    item = new QStandardItem("MsOldState");
    model_ecatDebugInfo->setItem(2,0,item);
    item = new QStandardItem(QString("%1").arg(info.masteroldState));
    model_ecatDebugInfo->setItem(2,1,item);

    item = new QStandardItem("stage");
    model_ecatDebugInfo->setItem(3,0,item);
    item = new QStandardItem(QString("%1").arg(info.stage));
    model_ecatDebugInfo->setItem(3,1,item);

    item = new QStandardItem("wkc_lost_max");
    model_ecatDebugInfo->setItem(4,0,item);
    item = new QStandardItem(QString("%1").arg(info.wkc_lost_max));
    model_ecatDebugInfo->setItem(4,1,item);

    item = new QStandardItem("wkc_count");
    model_ecatDebugInfo->setItem(5,0,item);
    item = new QStandardItem(QString("%1").arg(info.wkc_count));
    model_ecatDebugInfo->setItem(5,1,item);

    item = new QStandardItem("wkc_state");
    model_ecatDebugInfo->setItem(6,0,item);
    item = new QStandardItem(QString("%1").arg(info.wkc_state));
    model_ecatDebugInfo->setItem(6,1,item);

    item = new QStandardItem("opLoopCount");
    model_ecatDebugInfo->setItem(7,0,item);
    item = new QStandardItem(QString::number(info.opLoopCount,'f',1));
    model_ecatDebugInfo->setItem(7,1,item);


    item = new QStandardItem("cycle_us");
    model_ecatDebugInfo->setItem(8,0,item);
    item = new QStandardItem(QString("%1").arg(info.cycle_us));
    model_ecatDebugInfo->setItem(8,1,item);

    item = new QStandardItem("dcTimerShift");
    model_ecatDebugInfo->setItem(9,0,item);
    item = new QStandardItem(QString("%1").arg(info.dcTimerShift));
    model_ecatDebugInfo->setItem(9,1,item);

    item = new QStandardItem("refTime");
    model_ecatDebugInfo->setItem(10,0,item);
    item = new QStandardItem(QString("%1").arg(info.refTime));
    model_ecatDebugInfo->setItem(10,1,item);

    item = new QStandardItem("dc_diff_ns");
    model_ecatDebugInfo->setItem(11,0,item);
    item = new QStandardItem(QString("%1").arg(info.dc_diff_ns));
    model_ecatDebugInfo->setItem(11,1,item);

    item = new QStandardItem("pcSumTime");
    model_ecatDebugInfo->setItem(12,0,item);
    item = new QStandardItem(QString("%1").arg(info.pcSumTime));
    model_ecatDebugInfo->setItem(12,1,item);

    item = new QStandardItem("pcCycleCount");
    model_ecatDebugInfo->setItem(13,0,item);
    item = new QStandardItem(QString("%1").arg(info.pcCycleCount));
    model_ecatDebugInfo->setItem(13,1,item);

    item = new QStandardItem("ecatPeriodTimerMonitor_now");
    model_ecatDebugInfo->setItem(14,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatPeriodTimerMonitor_now/1000));
    model_ecatDebugInfo->setItem(14,1,item);

    item = new QStandardItem("ecatPeriodTimerMonitor_max");
    model_ecatDebugInfo->setItem(15,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatPeriodTimerMonitor_max/1000));
    model_ecatDebugInfo->setItem(15,1,item);

    item = new QStandardItem("ecatPeriodTimerMonitor_min");
    model_ecatDebugInfo->setItem(16,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatPeriodTimerMonitor_min/1000));
    model_ecatDebugInfo->setItem(16,1,item);

    item = new QStandardItem("ecatReceiveMonitor_now");
    model_ecatDebugInfo->setItem(17,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatReceiveMonitor_now/1000));
    model_ecatDebugInfo->setItem(17,1,item);

    item = new QStandardItem("ecatReceiveMonitor_max");
    model_ecatDebugInfo->setItem(18,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatReceiveMonitor_max/1000));
    model_ecatDebugInfo->setItem(18,1,item);

    item = new QStandardItem("ecatReceiveMonitor_min");
    model_ecatDebugInfo->setItem(19,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatReceiveMonitor_min/1000));
    model_ecatDebugInfo->setItem(19,1,item);

    item = new QStandardItem("ecatSendMonitor_now");
    model_ecatDebugInfo->setItem(20,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatSendMonitor_now/1000));
    model_ecatDebugInfo->setItem(20,1,item);

    item = new QStandardItem("ecatSendMonitor_max");
    model_ecatDebugInfo->setItem(21,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatSendMonitor_max/1000));
    model_ecatDebugInfo->setItem(21,1,item);

    item = new QStandardItem("ecatSendMonitor_min");
    model_ecatDebugInfo->setItem(22,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatSendMonitor_min/1000));
    model_ecatDebugInfo->setItem(22,1,item);

    item = new QStandardItem("ecatCustomMonitor_now");
    model_ecatDebugInfo->setItem(23,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatCustomMonitor_now/1000));
    model_ecatDebugInfo->setItem(23,1,item);

    item = new QStandardItem("ecatCustomMonitor_max");
    model_ecatDebugInfo->setItem(24,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatCustomMonitor_max/1000));
    model_ecatDebugInfo->setItem(24,1,item);

    item = new QStandardItem("ecatCustomMonitor_min");
    model_ecatDebugInfo->setItem(25,0,item);
    item = new QStandardItem(QString::number(info.ecatCustomMonitor_min/1000));
    model_ecatDebugInfo->setItem(25,1,item);


    for(int i=0;i<info.slaves_al.size();i++)
    {
        item = new QStandardItem("slave_al");
        model_ecatDebugInfo->setItem(i+26,0,item);
        item = new QStandardItem(QString("%1").arg(info.slaves_al[i]));
        model_ecatDebugInfo->setItem(i+26,1,item);
    }


    ui->tableView_ethercatDebugInfo->setModel(model_ecatDebugInfo);
    ui->tableView_ethercatDebugInfo->resizeColumnToContents(0);
    ui->tableView_ethercatDebugInfo->resizeColumnToContents(1);
    ui->tableView_ethercatDebugInfo->resizeColumnToContents(2);
    ui->tableView_ethercatDebugInfo->show();
}

void MainWindow::showDebugInfo_can(EthercatDebugInfo info)
{
    model_canDebugInfo->clear();
    //定义item
    QStandardItem* item = 0;

    item = new QStandardItem("periodTimer_now");
    model_canDebugInfo->setItem(0,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatPeriodTimerMonitor_now/1000));
    model_canDebugInfo->setItem(0,1,item);

    item = new QStandardItem("periodTimer_max");
    model_canDebugInfo->setItem(1,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatPeriodTimerMonitor_max/1000));
    model_canDebugInfo->setItem(1,1,item);

    item = new QStandardItem("periodTimer_min");
    model_canDebugInfo->setItem(2,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatPeriodTimerMonitor_min/1000));
    model_canDebugInfo->setItem(2,1,item);

    item = new QStandardItem("receive_now(us)");
    model_canDebugInfo->setItem(3,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatReceiveMonitor_now/1000));
    model_canDebugInfo->setItem(3,1,item);

    item = new QStandardItem("receive_max(us)");
    model_canDebugInfo->setItem(4,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatReceiveMonitor_max/1000));
    model_canDebugInfo->setItem(4,1,item);

    item = new QStandardItem("receive_min");
    model_canDebugInfo->setItem(5,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatReceiveMonitor_min/1000));
    model_canDebugInfo->setItem(5,1,item);

    item = new QStandardItem("send_now");
    model_canDebugInfo->setItem(6,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatSendMonitor_now/1000));
    model_canDebugInfo->setItem(6,1,item);

    item = new QStandardItem("send_max");
    model_canDebugInfo->setItem(7,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatSendMonitor_max/1000));
    model_canDebugInfo->setItem(7,1,item);

    item = new QStandardItem("send_min");
    model_canDebugInfo->setItem(8,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatSendMonitor_min/1000));
    model_canDebugInfo->setItem(8,1,item);

    item = new QStandardItem("custom_now");
    model_canDebugInfo->setItem(9,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatCustomMonitor_now/1000));
    model_canDebugInfo->setItem(9,1,item);

    item = new QStandardItem("custom_max");
    model_canDebugInfo->setItem(10,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatCustomMonitor_max/1000));
    model_canDebugInfo->setItem(10,1,item);

    item = new QStandardItem("custom_min");
    model_canDebugInfo->setItem(11,0,item);
    item = new QStandardItem(QString::number(info.ecatCustomMonitor_min/1000));
    model_canDebugInfo->setItem(11,1,item);

    item = new QStandardItem("MsCommandState");
    model_canDebugInfo->setItem(12,0,item);
    item = new QStandardItem(QString("%1").arg(info.masterCommandState));
    model_canDebugInfo->setItem(12,1,item);

    item = new QStandardItem("MsCurrentState");
    model_canDebugInfo->setItem(13,0,item);
    item = new QStandardItem(QString("%1").arg(info.masterCurrentState));
    model_canDebugInfo->setItem(13,1,item);

    item = new QStandardItem("MsOldState");
    model_canDebugInfo->setItem(14,0,item);
    item = new QStandardItem(QString("%1").arg(info.masteroldState));
    model_canDebugInfo->setItem(14,1,item);

    item = new QStandardItem("stage");
    model_canDebugInfo->setItem(15,0,item);
    item = new QStandardItem(QString("%1").arg(info.stage));
    model_canDebugInfo->setItem(15,1,item);

    item = new QStandardItem("wkc_lost_max");
    model_canDebugInfo->setItem(16,0,item);
    item = new QStandardItem(QString("%1").arg(info.wkc_lost_max));
    model_canDebugInfo->setItem(16,1,item);

    item = new QStandardItem("wkc_count");
    model_canDebugInfo->setItem(17,0,item);
    item = new QStandardItem(QString("%1").arg(info.wkc_count));
    model_canDebugInfo->setItem(17,1,item);

    item = new QStandardItem("wkc_state");
    model_canDebugInfo->setItem(18,0,item);
    item = new QStandardItem(QString("%1").arg(info.wkc_state));
    model_canDebugInfo->setItem(18,1,item);

    item = new QStandardItem("opLoopCount");
    model_canDebugInfo->setItem(19,0,item);
    item = new QStandardItem(QString::number(info.opLoopCount,'f',1));
    model_canDebugInfo->setItem(19,1,item);


    item = new QStandardItem("cycle_us");
    model_canDebugInfo->setItem(20,0,item);
    item = new QStandardItem(QString("%1").arg(info.cycle_us));
    model_canDebugInfo->setItem(20,1,item);

    item = new QStandardItem("dcTimerShift");
    model_canDebugInfo->setItem(21,0,item);
    item = new QStandardItem(QString("%1").arg(info.dcTimerShift));
    model_canDebugInfo->setItem(21,1,item);

    item = new QStandardItem("refTime");
    model_canDebugInfo->setItem(22,0,item);
    item = new QStandardItem(QString("%1").arg(info.refTime));
    model_canDebugInfo->setItem(22,1,item);

    item = new QStandardItem("rerfSumTime");
    model_canDebugInfo->setItem(23,0,item);
    item = new QStandardItem(QString("%1").arg(info.rerfSumTime));
    model_canDebugInfo->setItem(23,1,item);

    item = new QStandardItem("pcSumTime");
    model_canDebugInfo->setItem(24,0,item);
    item = new QStandardItem(QString("%1").arg(info.pcSumTime));
    model_canDebugInfo->setItem(24,1,item);

    item = new QStandardItem("pcCycleCount");
    model_canDebugInfo->setItem(25,0,item);
    item = new QStandardItem(QString("%1").arg(info.pcCycleCount));
    model_canDebugInfo->setItem(25,1,item);




//    for(int i=0;i<info.slaves_al.size();i++)
//    {
//        item = new QStandardItem("slave_al");
//        model_canDebugInfo->setItem(i+26,0,item);
//        item = new QStandardItem(QString("%1").arg(info.slaves_al[i]));
//        model_canDebugInfo->setItem(i+26,1,item);
//    }


    ui->tableView_canDebugInfo->setModel(model_canDebugInfo);
    ui->tableView_canDebugInfo->resizeColumnToContents(0);
    ui->tableView_canDebugInfo->resizeColumnToContents(1);
    ui->tableView_canDebugInfo->resizeColumnToContents(2);
    ui->tableView_canDebugInfo->show();
}

void MainWindow::showDebugInfo_modbus(EthercatDebugInfo info)
{
    model_modbusDebugInfo->clear();
    //定义item
    QStandardItem* item = 0;

    item = new QStandardItem("periodTimer_now");
    model_modbusDebugInfo->setItem(0,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatPeriodTimerMonitor_now/1000));
    model_modbusDebugInfo->setItem(0,1,item);

    item = new QStandardItem("periodTimer_max");
    model_modbusDebugInfo->setItem(1,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatPeriodTimerMonitor_max/1000));
    model_modbusDebugInfo->setItem(1,1,item);

    item = new QStandardItem("periodTimer_min");
    model_modbusDebugInfo->setItem(2,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatPeriodTimerMonitor_min/1000));
    model_modbusDebugInfo->setItem(2,1,item);

    item = new QStandardItem("receive_now(us)");
    model_modbusDebugInfo->setItem(3,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatReceiveMonitor_now/1000));
    model_modbusDebugInfo->setItem(3,1,item);

    item = new QStandardItem("receive_max(us)");
    model_modbusDebugInfo->setItem(4,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatReceiveMonitor_max/1000));
    model_modbusDebugInfo->setItem(4,1,item);

    item = new QStandardItem("receive_min");
    model_modbusDebugInfo->setItem(5,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatReceiveMonitor_min/1000));
    model_modbusDebugInfo->setItem(5,1,item);

    item = new QStandardItem("send_now");
    model_modbusDebugInfo->setItem(6,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatSendMonitor_now/1000));
    model_modbusDebugInfo->setItem(6,1,item);

    item = new QStandardItem("send_max");
    model_modbusDebugInfo->setItem(7,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatSendMonitor_max/1000));
    model_modbusDebugInfo->setItem(7,1,item);

    item = new QStandardItem("send_min");
    model_modbusDebugInfo->setItem(8,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatSendMonitor_min/1000));
    model_modbusDebugInfo->setItem(8,1,item);

    item = new QStandardItem("custom_now");
    model_modbusDebugInfo->setItem(9,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatCustomMonitor_now/1000));
    model_modbusDebugInfo->setItem(9,1,item);

    item = new QStandardItem("custom_max");
    model_modbusDebugInfo->setItem(10,0,item);
    item = new QStandardItem(QString("%1").arg(info.ecatCustomMonitor_max/1000));
    model_modbusDebugInfo->setItem(10,1,item);

    item = new QStandardItem("custom_min");
    model_modbusDebugInfo->setItem(11,0,item);
    item = new QStandardItem(QString::number(info.ecatCustomMonitor_min/1000));
    model_modbusDebugInfo->setItem(11,1,item);

    item = new QStandardItem("MsCommandState");
    model_modbusDebugInfo->setItem(12,0,item);
    item = new QStandardItem(QString("%1").arg(info.masterCommandState));
    model_modbusDebugInfo->setItem(12,1,item);

    item = new QStandardItem("MsCurrentState");
    model_modbusDebugInfo->setItem(13,0,item);
    item = new QStandardItem(QString("%1").arg(info.masterCurrentState));
    model_modbusDebugInfo->setItem(13,1,item);

    item = new QStandardItem("MsOldState");
    model_modbusDebugInfo->setItem(14,0,item);
    item = new QStandardItem(QString("%1").arg(info.masteroldState));
    model_modbusDebugInfo->setItem(14,1,item);

    item = new QStandardItem("stage");
    model_modbusDebugInfo->setItem(15,0,item);
    item = new QStandardItem(QString("%1").arg(info.stage));
    model_modbusDebugInfo->setItem(15,1,item);

    item = new QStandardItem("wkc_lost_max");
    model_modbusDebugInfo->setItem(16,0,item);
    item = new QStandardItem(QString("%1").arg(info.wkc_lost_max));
    model_modbusDebugInfo->setItem(16,1,item);

    item = new QStandardItem("wkc_count");
    model_modbusDebugInfo->setItem(17,0,item);
    item = new QStandardItem(QString("%1").arg(info.wkc_count));
    model_modbusDebugInfo->setItem(17,1,item);

    item = new QStandardItem("wkc_state");
    model_modbusDebugInfo->setItem(18,0,item);
    item = new QStandardItem(QString("%1").arg(info.wkc_state));
    model_modbusDebugInfo->setItem(18,1,item);

    item = new QStandardItem("opLoopCount");
    model_modbusDebugInfo->setItem(19,0,item);
    item = new QStandardItem(QString::number(info.opLoopCount,'f',1));
    model_modbusDebugInfo->setItem(19,1,item);


    item = new QStandardItem("cycle_us");
    model_modbusDebugInfo->setItem(20,0,item);
    item = new QStandardItem(QString("%1").arg(info.cycle_us));
    model_modbusDebugInfo->setItem(20,1,item);

    item = new QStandardItem("dcTimerShift");
    model_modbusDebugInfo->setItem(21,0,item);
    item = new QStandardItem(QString("%1").arg(info.dcTimerShift));
    model_modbusDebugInfo->setItem(21,1,item);

    item = new QStandardItem("refTime");
    model_modbusDebugInfo->setItem(22,0,item);
    item = new QStandardItem(QString("%1").arg(info.refTime));
    model_modbusDebugInfo->setItem(22,1,item);

    item = new QStandardItem("rerfSumTime");
    model_modbusDebugInfo->setItem(23,0,item);
    item = new QStandardItem(QString("%1").arg(info.rerfSumTime));
    model_modbusDebugInfo->setItem(23,1,item);

    item = new QStandardItem("pcSumTime");
    model_modbusDebugInfo->setItem(24,0,item);
    item = new QStandardItem(QString("%1").arg(info.pcSumTime));
    model_modbusDebugInfo->setItem(24,1,item);

    item = new QStandardItem("pcCycleCount");
    model_modbusDebugInfo->setItem(25,0,item);
    item = new QStandardItem(QString("%1").arg(info.pcCycleCount));
    model_modbusDebugInfo->setItem(25,1,item);




//    for(int i=0;i<info.slaves_al.size();i++)
//    {
//        item = new QStandardItem("slave_al");
//        model_modbusDebugInfo->setItem(i+26,0,item);
//        item = new QStandardItem(QString("%1").arg(info.slaves_al[i]));
//        model_modbusDebugInfo->setItem(i+26,1,item);
//    }


    ui->tableView_modbusDebugInfo->setModel(model_modbusDebugInfo);
    ui->tableView_modbusDebugInfo->resizeColumnToContents(0);
    ui->tableView_modbusDebugInfo->resizeColumnToContents(1);
    ui->tableView_modbusDebugInfo->resizeColumnToContents(2);
    ui->tableView_modbusDebugInfo->show();
}

void MainWindow::showBatteryInfo(BatteryInformation batteryInfo)
{
    model_batteryInfo->clear();
    //定义item
    QStandardItem* item = 0;

    item = new QStandardItem("tempture");
    model_batteryInfo->setItem(0,0,item);
    item = new QStandardItem(QString::number(batteryInfo.batteryTempture,'f',3));
    model_batteryInfo->setItem(0,1,item);

    item = new QStandardItem("Voltage");
    model_batteryInfo->setItem(1,0,item);
    item = new QStandardItem(QString::number(batteryInfo.batterySumVoltage,'f',3));
    model_batteryInfo->setItem(1,1,item);

    item = new QStandardItem("Currency");
    model_batteryInfo->setItem(2,0,item);
    item = new QStandardItem(QString::number(batteryInfo.batteryCurrentCurrency,'f',3));
    model_batteryInfo->setItem(2,1,item);

    item = new QStandardItem("LeftLightmodRatio");
    model_batteryInfo->setItem(3,0,item);
    item = new QStandardItem(QString::number(batteryInfo.batteryLeftLightmodRatio,'f',3));
    model_batteryInfo->setItem(3,1,item);

    item = new QStandardItem("LeftLightmodVolume");
    model_batteryInfo->setItem(4,0,item);
    item = new QStandardItem(QString::number(batteryInfo.batteryLeftLightmodVolume,'f',3));
    model_batteryInfo->setItem(4,1,item);

    item = new QStandardItem("CycleNumber");
    model_batteryInfo->setItem(5,0,item);
    item = new QStandardItem(QString::number(batteryInfo.batteryCycleNumber,'f',3));
    model_batteryInfo->setItem(5,1,item);

    item = new QStandardItem("DesignVolume");
    model_batteryInfo->setItem(6,0,item);
    item = new QStandardItem(QString::number(batteryInfo.batteryDesignVolume,'f',3));
    model_batteryInfo->setItem(6,1,item);

    item = new QStandardItem("manufatureData");
    model_batteryInfo->setItem(7,0,item);
    item = new QStandardItem(QString("%1").arg(batteryInfo.manufatureData));
    model_batteryInfo->setItem(7,1,item);


    item = new QStandardItem("balanceStatus");
    model_batteryInfo->setItem(8,0,item);
    item = new QStandardItem(QString("%1").arg(batteryInfo.balanceStatus));
    model_batteryInfo->setItem(8,1,item);

    item = new QStandardItem("errorStatus");
    model_batteryInfo->setItem(9,0,item);
    item = new QStandardItem(QString("%1").arg(batteryInfo.errorStatus));
    model_batteryInfo->setItem(9,1,item);

    item = new QStandardItem("Versition");
    model_batteryInfo->setItem(10,0,item);
    item = new QStandardItem(QString("%1").arg(batteryInfo.softWareVersition));
    model_batteryInfo->setItem(10,1,item);

    item = new QStandardItem("fet");
    model_batteryInfo->setItem(11,0,item);
    item = new QStandardItem(QString("%1").arg(batteryInfo.fet));
    model_batteryInfo->setItem(11,1,item);

    item = new QStandardItem("SerialCount");
    model_batteryInfo->setItem(12,0,item);
    item = new QStandardItem(QString("%1").arg(batteryInfo.batterySerialCount));
    model_batteryInfo->setItem(12,1,item);

    item = new QStandardItem("ntcCount");
    model_batteryInfo->setItem(13,0,item);
    item = new QStandardItem(QString("%1").arg(batteryInfo.ntcCount));
    model_batteryInfo->setItem(13,1,item);


    for(int i=0;i<batteryInfo.ntcData.size();i++)
    {
        item = new QStandardItem("ntcData");
        model_batteryInfo->setItem(i+14,0,item);
        item = new QStandardItem(QString("%1").arg(batteryInfo.ntcData[i]));
        model_batteryInfo->setItem(i+14,1,item);
    }

    ui->tableView_batteryInfo->setModel(model_batteryInfo);
    ui->tableView_batteryInfo->resizeColumnToContents(0);
    ui->tableView_batteryInfo->resizeColumnToContents(1);
    ui->tableView_batteryInfo->resizeColumnToContents(2);
    ui->tableView_batteryInfo->show();
}

void MainWindow::showDebugInfo_fleet(FleetDebugInfo info)
{
    model_fleetDebugInfo->clear();
    //定义item
    QStandardItem* item = 0;

    QString statusStr;
    if(E_FLEET_TASK_STATUS_IDILE==info.taskStatus)
    {
        statusStr="停止";
    }
    else if(E_FLEET_TASK_STATUS_MOVING==info.taskStatus)
    {
        statusStr="执行中";
    }
    else if(E_FLEET_TASK_STATUS_CEASE==info.taskStatus)
    {
        statusStr="暂停";
    }

    QString isIdileStr;
    if(true==info.isLoopIdile)
    {
        isIdileStr="空闲";
    }
    else if(false==info.isLoopIdile)
    {
        isIdileStr="忙";
    }

    item = new QStandardItem("状态");
    model_fleetDebugInfo->setItem(0,0,item);
    item = new QStandardItem(statusStr);
    model_fleetDebugInfo->setItem(0,1,item);

    item = new QStandardItem("队列大小");
    model_fleetDebugInfo->setItem(1,0,item);
    item = new QStandardItem(QString::number(info.commandQueueSize));
    model_fleetDebugInfo->setItem(1,1,item);

    item = new QStandardItem("执行器空闲");
    model_fleetDebugInfo->setItem(2,0,item);
    item = new QStandardItem(isIdileStr);
    model_fleetDebugInfo->setItem(2,1,item);

    item = new QStandardItem("最后加入行号");
    model_fleetDebugInfo->setItem(3,0,item);
    item = new QStandardItem(QString::number(info.commandIndex));
    model_fleetDebugInfo->setItem(3,1,item);

    item = new QStandardItem("执行行号");
    model_fleetDebugInfo->setItem(4,0,item);
    item = new QStandardItem(QString::number(info.executingLine));
    model_fleetDebugInfo->setItem(4,1,item);

    item = new QStandardItem("执行指令类型");
    model_fleetDebugInfo->setItem(5,0,item);
    item = new QStandardItem(QString::number(info.executingCommandType));
    model_fleetDebugInfo->setItem(5,1,item);


    ui->tableView_fleetDebugInfo->setModel(model_fleetDebugInfo);
    ui->tableView_fleetDebugInfo->resizeColumnToContents(0);
    ui->tableView_fleetDebugInfo->resizeColumnToContents(1);
    ui->tableView_fleetDebugInfo->resizeColumnToContents(2);
    ui->tableView_fleetDebugInfo->show();
}

void MainWindow::showVehicleInfo()
{
    if(true==ui->checkBox_isUpdate_vehicle_info->isChecked())
    {
        double historyOdomOut, historyTimeOut,customOdomOut, customeTimeOut;
        p_powerManger->getOdometer_positionManage(userInfo,historyOdomOut, historyTimeOut,customOdomOut, customeTimeOut);
        ui->lineEdit_vehicle_historyOdom->setText(QString::number(historyOdomOut,'f',0));
        ui->lineEdit_vehicle_history_time->setText(QString::number(historyTimeOut,'f',0));
        ui->lineEdit_vehicle_custom_odom->setText(QString::number(customOdomOut,'f',0));
        ui->lineEdit_vehicle_custom_time->setText(QString::number(customeTimeOut,'f',0));
        VehicleVelocity velocityOut;
        p_powerManger->getVehicleSpeedFeedback(userInfo,velocityOut);
        ui->lineEdit_vehicle_feedback_vx->setText(QString::number(velocityOut.x_move,'f',2));
        ui->lineEdit_vehicle_feedback_vy->setText(QString::number(velocityOut.y_move,'f',2));
        ui->lineEdit_vehicle_feedback_vr->setText(QString::number(velocityOut.z_rotate,'f',2));

    }
}

void MainWindow::showStorageInfo()
{
    //显示存储及ＣＰＵ情况
    double tmpCpu;
    p_powerManger->getCpuInfo(userInfo,tmpCpu);
    ui->lineEdit_2->setText(QString::number(tmpCpu,10,2));


    double usedVolume,freeVolume;
    p_powerManger->getRamInfo(userInfo,usedVolume,freeVolume);
    ui->lineEdit_3->setText(QString::number(usedVolume,10,2));
    ui->lineEdit_4->setText(QString::number(freeVolume,10,2));

    p_powerManger->getHardDiskInfo(userInfo,usedVolume,freeVolume);
    ui->lineEdit_6->setText(QString::number(usedVolume,10,2));
    ui->lineEdit_5->setText(QString::number(freeVolume,10,2));
}

void MainWindow::showMessageInfo()
{
    //显示消息
    std::vector<struct Message> messageVector;
    p_powerManger->updateControllerMessage(   userInfo, messageVector );
    QString messageText;
    if(messageSize!=messageVector.size())
    {
        ui->listWidget_2->clear();
        messageText.clear();
        for(int i=0;i<messageVector.size();i++)
        {
            messageText=QString::number(messageVector[i].messageCode)
                    +QString::fromStdString(messageVector[i].MessageInformation);

            ui->listWidget_2->addItem(messageText);

        }
        messageSize=messageVector.size();

    }
}

void MainWindow::showMotorStatusInfo()
{
    QVector<ServoState> pData = robCtl->getServoDataRobot( robotId );

    unsigned short tmpStatusOut;
    unsigned short tmpErrorCodeOut=0;
    unsigned int vendorIdOut;
    if(pData.size()){
        int count=-1;
        if( ++count < pData.size()){
            robCtl->getMotorVendorId(robotId,count,vendorIdOut);
            robCtl->getMotorStatusWord(robotId,count,tmpStatusOut);

                ui->label_err_0->setText( QString::number( pData.at( count ).errorCode) );

            ui->label_pos_0->setText( QString::number( pData.at( count ).position) );

            ui->label_14->setText( QString::number( tmpStatusOut ));
        }
        if( ++count < pData.size()){
            robCtl->getMotorVendorId(robotId,count,vendorIdOut);
            robCtl->getMotorStatusWord(robotId,count,tmpStatusOut);

                ui->label_err_1->setText( QString::number( pData.at( count ).errorCode) );

            ui->label_pos_1->setText( QString::number( pData.at( count ).position) );

                  ui->label_15->setText( QString::number( tmpStatusOut) );
        }
        if( ++count < pData.size()){
            robCtl->getMotorVendorId(robotId,count,vendorIdOut);
            robCtl->getMotorStatusWord(robotId,count,tmpStatusOut);

                ui->label_err_2->setText( QString::number( pData.at( count ).errorCode) );

            ui->label_pos_2->setText( QString::number( pData.at( count ).position) );

                ui->label_16->setText( QString::number( tmpStatusOut) );
        }
        if( ++count < pData.size()){
            robCtl->getMotorVendorId(robotId,count,vendorIdOut);
            robCtl->getMotorStatusWord(robotId,count,tmpStatusOut);

                ui->label_err_3->setText( QString::number( pData.at( count ).errorCode) );

            ui->label_pos_3->setText( QString::number( pData.at( count ).position) );

                ui->label_17->setText( QString::number( tmpStatusOut) );
        }
        if( ++count < pData.size()){
            robCtl->getMotorVendorId(robotId,count,vendorIdOut);
            robCtl->getMotorStatusWord(robotId,count,tmpStatusOut);

                ui->label_err_4->setText( QString::number( pData.at( count ).errorCode) );

            ui->label_pos_4->setText( QString::number( pData.at( count ).position) );

                    ui->label_18->setText( QString::number( tmpStatusOut) );
        }
        if( ++count < pData.size()){
            robCtl->getMotorVendorId(robotId,count,vendorIdOut);
            robCtl->getMotorStatusWord(robotId,count,tmpStatusOut);

                ui->label_err_5->setText( QString::number( pData.at( count ).errorCode) );

            ui->label_pos_5->setText( QString::number( pData.at( count ).position) );

                ui->label_19->setText( QString::number( tmpStatusOut) );
        }
    }



    //显示servoOn状态

    if(true==p_powerManger->robotManager->robotsMap.contains(robotId))
    {

        if(true==p_powerManger->robotManager->robotsMap.value(robotId)
                ->threadMotionEngine->mcControllerInterpreter->isServoOn())
        {
            ui->radioButton->setChecked(true);
        }
        else
        {
            ui->radioButton->setChecked(false);
        }
    }

//    int tmpStatus=p_powerManger->robotManager->robotsMap.value(robotId)
//                    ->threadMotionEngine->mcControllerInterpreter->getStatus();
//    ui->lineEdit_mcInterpreterStatus->setText(QString::number(tmpStatus));
}

void MainWindow::showPointCloudSafeRatio(std::vector<string> &sensorNameOut, std::vector<double> &sensorSafeRatioOut)
{

    model_poindCloudSafeInfo->clear();
    //定义item
    QStandardItem* item = 0;

    for(int i=0;i<sensorNameOut.size();i++)
    {
        item = new QStandardItem(QString::fromStdString(sensorNameOut[i]));
        model_poindCloudSafeInfo->setItem(i,0,item);
        item = new QStandardItem(QString::number(sensorSafeRatioOut[i]));
        model_poindCloudSafeInfo->setItem(i,1,item);
    }

    ui->tableView_pointCloudSafeRatio->setModel(model_poindCloudSafeInfo);
//    ui->tableView_pointCloudSafeRatio->resizeColumnToContents(0);//为什么coredump
//    ui->tableView_pointCloudSafeRatio->resizeColumnToContents(1);
//    ui->tableView_pointCloudSafeRatio->resizeColumnToContents(2);
    ui->tableView_pointCloudSafeRatio->show();
}

void MainWindow::showFleetInfo()
{
    if(false==ui->checkBox_isUpdateFleetInfo->isChecked())
    {
        return ;
    }
    //socket fleet
    std::queue<std::string> fleetCommandLogOut;
    p_powerManger->getSocketFleetCommandLog(fleetCommandLogOut);
    ui->textEdit_socketFleetRequest->clear();
    int tmpSize=fleetCommandLogOut.size();
    for(int i=0;i<tmpSize;i++)
    {
        ui->textEdit_socketFleetRequest->append(QString::fromStdString(fleetCommandLogOut.front()));
        fleetCommandLogOut.pop();
    }
    ui->textEdit_socketFleetRequest->moveCursor(QTextCursor::EndOfLine);

    //modbus fleet
    p_powerManger->getModbusFleetCommandLog(fleetCommandLogOut);
    ui->textEdit_modbusFleetRequest->clear();
    for(int i=0;i<fleetCommandLogOut.size();i++)
    {
        ui->textEdit_modbusFleetRequest->append(QString::fromStdString(fleetCommandLogOut.front()));
        fleetCommandLogOut.pop();
    }
    ui->textEdit_modbusFleetRequest->moveCursor(QTextCursor::EndOfLine);


    return;
}


void MainWindow::timeOut_slot()
{
    timerTickCount++;
    if(1==debugFlag)
    {
        qDebug()<<"MainWindow::timeOut_slot() In";
    }

    if( !p_powerManger )
    {
        if(1==debugFlag)
        {
            qDebug()<<"MainWindow::timeOut_slot() Out";
        }
        return;
    }

    int tmpRobotId;
    if(false==p_powerManger->getCurrentRobotId(tmpRobotId))
    {
        if(1==debugFlag)
        {
            qDebug()<<"MainWindow::timeOut_slot() Out";
        }
        return;
    }
    else
    {
        robotId=tmpRobotId;
    }
    if( robotId<1 )
    {
        if(1==debugFlag)
        {
            qDebug()<<"MainWindow::timeOut_slot() Out";
        }
        return;
    }
    ui->label_currentRobotId->setText(QString::number(robotId));


    //手动喂狗
    if(true==jogOnFlag)
    {
        p_powerManger->feedDog();
    }


    // float 速率要加锁
    UpdateDataLv2  updateDataLv2;
    p_powerManger-> updateControllerInfoLevel2( userInfo, updateDataLv2 );
    showPoitionInfo(updateDataLv2);
    showProgramRunningInfo(updateDataLv2);

    //显示调试信息
    showDebugInfo();

    showMotorStatusInfo();

    showMessageInfo();

    showStorageInfo();

    //ultrasonic
    showUltrasonicInfo();

    showVehicleInfo();


    // robotManager->robotsMap.value(robotId)->threadProgramEngine->openFile( robotManager->robotsMap.value(robotId)->defaultFile );
  //  ui->lineEdit_run_file_uf->setText( "" );
 /*
    int returnUToolNum ;
    p_powerManger->getUToolActive(  userInfo,   returnUToolNum);
    int returnUFrameNum;
     p_powerManger->getUFrameActive(  userInfo,   returnUFrameNum);

     ui->spinBox_uf->setValue( returnUFrameNum );
     ui->spinBox_ut->setValue( returnUToolNum );
*/

    if(true==ui->checkBox_pointCloud_check->isChecked())
    {
        std::vector<string> sensorNameOut;
        std::vector<double> sensorSafeRatioOut;
        bool isCheckOnCloud;
        p_powerManger->getPointCloudSafeStatus(sensorNameOut,sensorSafeRatioOut,isCheckOnCloud);
        showPointCloudSafeRatio(sensorNameOut,sensorSafeRatioOut);
        ui->checkBox_pointCloud_check_status->setChecked(isCheckOnCloud);

    }

    showFleetInfo();

    if(1==debugFlag)
    {
        qDebug()<<"MainWindow::timeOut_slot() Out";
    }
    ui->label_timerTickCount->setText(QString::number(timerTickCount));

}

void MainWindow::move_slot()
{
    if( !p_powerManger )
        return;
//    if( !p_powerManger->eCat )
//        return;
//    if( !robCtl->isInitOk )
//        return;

    qDebug()<<"不支持!";
}

void MainWindow::showUltrasonicInfo()
{
    if( !p_powerManger )
        return;
    QVector<double> distanceResultOut;
    p_powerManger->getUltrasonicDetectDistance(distanceResultOut);
    QVector<int>  deviceRequestCountOut;
    p_powerManger->getUltrasonicStatus(deviceRequestCountOut);
    std::vector<string> sensorNames;
    p_powerManger->getUltrasonicSensorName(sensorNames);

    ui->textEdit_ultrasonicDistance->clear();
    QString tmpLineStr;
    for(int i=0;i<distanceResultOut.size();i++)
    {
        tmpLineStr=QString::fromStdString(sensorNames[i])+" ,";
        tmpLineStr+=QString::number(distanceResultOut[i],10,0);
        tmpLineStr+="  ,响应差数 "+QString::number(deviceRequestCountOut[i]);
        ui->textEdit_ultrasonicDistance->append(tmpLineStr);
    }


    std::vector<double> safeStatusOut;
    bool isCheckEnableOut;
    p_powerManger->getUltrasonicSensorSafeStatus(safeStatusOut,isCheckEnableOut);
    ui->checkBox_ultrasonic_check_status->setChecked(isCheckEnableOut);

    if(4==safeStatusOut.size())
    {
        ui->lineEdit_ultrasonic_safeRatio_1->setText(QString::number(safeStatusOut[0]));
         ui->lineEdit_ultrasonic_safeRatio_2->setText(QString::number(safeStatusOut[1]));
          ui->lineEdit_ultrasonic_safeRatio_3->setText(QString::number(safeStatusOut[2]));
           ui->lineEdit_ultrasonic_safeRatio_4->setText(QString::number(safeStatusOut[3]));
    }

    //探测模式
    E_BARRIER_TETECT_MODE modeOut;
    QString modeStr;
    p_powerManger->getBarriorDetectMode(modeOut);
    switch(modeOut)
    {
    case E_BARRIER_TETECT_MODE_NONE:
    {
        modeStr="无";
        break;
    }
    case E_BARRIER_TETECT_MODE_FRONT:
    {
        modeStr="前";
        break;
    }
    case E_BARRIER_TETECT_MODE_BACK:
    {
        modeStr="后";
        break;
    }
    case E_BARRIER_TETECT_MODE_LEFT:
    {
        modeStr="左";
        break;
    }
    case E_BARRIER_TETECT_MODE_RIGHT:
    {
        modeStr="右";
        break;
    }
    case E_BARRIER_TETECT_MODE_ROTATION:
    {
        modeStr="旋转";
        break;
    }
    case E_BARRIER_TETECT_MODE_FRONT_LEFT:
    {
        modeStr="前左";
        break;
    }
    case E_BARRIER_TETECT_MODE_FRONT_RIGHT:
    {
        modeStr="前右";
        break;
    }
    case E_BARRIER_TETECT_MODE_BACK_LEFT:
    {
        modeStr="后左";
        break;
    }
    case E_BARRIER_TETECT_MODE_BACK_RIGHT:
    {
        modeStr="后右";
        break;
    }
    default:
    {
         modeStr="不识别的模式";
    }

    }
    ui->lineEdit_barriorDetectMode->setText(modeStr);
}

void MainWindow::showDebugInfo()
{
    if(true==ui->checkBox_debugInfoUpdateEnable->isChecked())
    {
        MotionDebugInfo motionDebugInfo;
        p_powerManger->getMotionServerDebugInfo(userInfo, motionDebugInfo);
        std::vector<ProgramEngineDebugInfo> programEngineDebugInfoList;
        p_powerManger->getProgramEngineDebugInfoList(userInfo, programEngineDebugInfoList);
        showDebugInfo_motionServer(motionDebugInfo);
        showDebugInfo_programEngine(programEngineDebugInfoList);
        TaskManagerInfo taskInfo;
        p_powerManger->getTaskInfo(userInfo,taskInfo);
        showDebugInfo_taskInfo(taskInfo);
        VirtualLineDebugInfo virtualLineInfo;
        p_powerManger->getVirtualLineControlDebugInfo(userInfo, virtualLineInfo);
        showDebugInfo_virtualLineControl(virtualLineInfo);
        FleetDebugInfo fleetInfoOut;
        if(NULL!=fleetService)
        {
            fleetService->getFleetDebugInfo(fleetInfoOut);
            showDebugInfo_fleet(fleetInfoOut);
        }

    }
    if(true==ui->checkBox_ecatInfoUpdateEnable->isChecked())
    {
        EthercatDebugInfo ecatDebugInfo;
        p_powerManger->getEthercatDebugInfo(userInfo, ecatDebugInfo);
        showDebugInfo_ethercat(ecatDebugInfo);
    }
    if(true==ui->checkBox_canInfoUpdateEnable->isChecked())
    {
        EthercatDebugInfo ecatDebugInfo;
        p_powerManger->getCanDebugInfo(userInfo, ecatDebugInfo);
        showDebugInfo_can(ecatDebugInfo);
    }
    if(true==ui->checkBox_modbusInfoUpdateEnable->isChecked())
    {
        EthercatDebugInfo ecatDebugInfo;
        bool isModbusRtu=ui->comboBox_isModbusRtu->currentIndex();
        int busIndex=ui->lineEdit_modebus_busIndex->text().toInt();
        p_powerManger->getModbusDebugInfo(userInfo, isModbusRtu, busIndex,ecatDebugInfo);
        showDebugInfo_modbus(ecatDebugInfo);
    }
    if(true==ui->checkBox_batteryUpdate->isChecked())
    {
        BatteryInformation batteryInfo;
        int tmpKey=p_powerManger->getBatteryInfo(batteryInfo);
        if(1==tmpKey)
        {
           showBatteryInfo(batteryInfo);
           ui->label_batteryStatus->setText("ok");
        }
        else
        {
            ui->label_batteryStatus->setText(QString("error%1").arg(tmpKey));
        }

    }

}



void MainWindow::on_pushButton_quick_stop_clicked()
{
    if( !p_powerManger )
        return;
//    if( !p_powerManger->eCat )
//        return;
//    if( !robCtl->isInitOk )
//        return;

    robCtl->quickStopRobot( -1 );
}

void MainWindow::on_spinBox_time_valueChanged(int arg1)
{
    timer->setInterval( arg1 );
}

void MainWindow::on_checkBox_on_off_toggled(bool checked)
{
    if( !p_powerManger )
        return;
    if( checked )
    {
        qDebug()<< "servoOnrobot(  ) : "<<  robotId  ;
        p_powerManger->servoOnrobot(robotId);
//       p_powerManger->robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->servoOn();
       servoOnState=1;
    }
    else
    {
        p_powerManger->servoOffCurrentRobot();
       //p_powerManger->robotManager->robotsMap.value(robotId)->threadMotionEngine->mcControllerInterpreter->servoOff();
        servoOnState=0;


    }
}


void MainWindow::on_pushButton_run_clicked()
{
    if( !p_powerManger )
        return;
    QMessageBox message(QMessageBox::Question, "提示", "programRun"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }

    int returnFlag;
    p_powerManger->programRun(userInfo,returnFlag);

}

void MainWindow::on_pushButton_open_file_clicked()
{
    if( !p_powerManger )
        return;

    QString str= ui->lineEdit_filename->text();
    int cut=str.indexOf("/");
    if( cut>0 )
        str=str.mid(cut+1);
    p_powerManger->robotManager->robotsMap.value( robotId )->openFile( str );

}

void MainWindow::on_pushButton_default_clicked()
{
    if( !p_powerManger )
        return;

    QMessageBox message(QMessageBox::Question, "提示", "设置缺省程序？"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }

    int returnFlag;
    p_powerManger->setDefaultProgramFile(userInfo,ui->lineEdit_filename->text().toStdString(),returnFlag);

//    p_powerManger->robotManager->robotsMap.value( robotId )->readDefaultFileSetting();
//    QString strFile=p_powerManger->robotManager->robotsMap.value( robotId )->defaultFile;
//    ui->lineEdit_filename->setText( strFile.section("/",8,8) );
}

void MainWindow::on_pushButton_stop_clicked()
{
    if( !p_powerManger )
        return;
    int returnFlag;
    p_powerManger->programReset(userInfo,returnFlag);
    jogOnFlag=false;
}

//void MainWindow::on_pushButton_reset_clicked()
//{
//    p_powerManger->robotManager->robotsMap.value( robotId )->resetProgram();
//}

void MainWindow::on_pushButton_clear_clicked()
{
    int returnFlag;
    p_powerManger->setAllMsgClear(userInfo, returnFlag);
    //robCtl->resetErrorRobot( robotId );
}

void MainWindow::on_spinBox_uf_valueChanged(int arg1)
{
    if( !p_powerManger )
        return;

    int returnFlag;
    p_powerManger->setUFrameActive(  userInfo,  arg1,  returnFlag );
}

void MainWindow::on_spinBox_ut_valueChanged(int arg1)
{
    if( !p_powerManger )
        return;

    int returnFlag;
    p_powerManger->setUToolActive(  userInfo,  arg1,  returnFlag );
}

void MainWindow::on_spinBox_manual_speed_valueChanged(int arg1)
{
    if( !p_powerManger )
        return;

    int returnFlag;
    p_powerManger->setManualSpeedPercent(  userInfo,  arg1,  returnFlag );

    // int speed= ui->spinBox_manual_speed->value();
    // int setManualSpeedPercent(UserInfo userInfo,int nSpeedValue,int &returnFlag);
    // int setAutoSpeedPercent(UserInfo userInfo,int nSpeedValue,int &returnFlag);
}

//+
void MainWindow::on_pushButton_jog_run_2_pressed()
{
    int returnFlag;
    p_powerManger->setManualSpeedPercent(  userInfo,  ui->spinBox_manual_speed->value(),  returnFlag );
    p_powerManger->jogRun( userInfo, ui->comboBox_axis->currentIndex(), 1 ,returnFlag);
    jogOnFlag=true;

}
//+
void MainWindow::on_pushButton_jog_run_2_released()
{
    int returnFlag;
    p_powerManger->programReset(userInfo,returnFlag);
    jogOnFlag=false;
}

void MainWindow::on_pushButton_jog_run_3_pressed()
{

    int returnFlag;
    p_powerManger->setManualSpeedPercent(  userInfo,  ui->spinBox_manual_speed->value(),  returnFlag );
    p_powerManger->jogRun( userInfo, ui->comboBox_axis->currentIndex(), 0 ,returnFlag);
    jogOnFlag=true;
}

void MainWindow::on_pushButton_jog_run_3_released()
{
    int returnFlag;
    p_powerManger->programReset(userInfo,returnFlag);
    jogOnFlag=false;
}

void MainWindow::on_pushButton_stop_2_clicked()
{
    int returnFlag;
//    p_powerManger->programReset(userInfo,returnFlag);
    p_powerManger->programCease(userInfo,returnFlag);

    jogOnFlag=false;
}

void MainWindow::on_spinBox_vrep_speed_valueChanged(int arg1)
{
    if( !p_powerManger )
        return;

}

//#include <QRegExp>
//void MainWindow::on_lineEdit_textChanged(const QString &arg1)
//{
//    if( !p_powerManger )
//        return;

//    QRegExp ex;
//    ex.setPattern( "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");
//#ifdef  D_USE_VREP
//    if( ex.exactMatch( arg1 ) )
//    {
//        // ((EcatMasterVrep*)robCtl->ecatmaster)->tcpVrep->remoteIpAddress = arg1;
//        qDebug()<< "========== 修改tcp IP: "<< arg1;
//    }
//#endif
//}

void MainWindow::on_pushButton_setZeroPoint_clicked()
{
    if( !p_powerManger )
        return;
    QMessageBox message(QMessageBox::Question, "提示", "是否记录当前位置为机器人所有轴的零点！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    int returnflag=0;
    qDebug()<<" MainWindow::on_pushButton_setZeroPoint_clicked()";
    p_powerManger->setRobotAllAxisCaliberate( userInfo, returnflag );
    if(1==returnflag)
    {
        QMessageBox::information(this,QStringLiteral("提示"),QStringLiteral("一键校零成功"));
    }
    else
    {
        QMessageBox::information(this,QStringLiteral("提示"),QStringLiteral("一键校零失败"));
    }

}

void MainWindow::on_pushButton_singleAxisCalibrate_clicked()
{
    if( !p_powerManger )
        return;


    QMessageBox message(QMessageBox::Question, "提示", "是否记录当前位置为机器人选定轴的零点！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    int returnflag=0;
    p_powerManger->setRobotSingleAxisCaliberate(userInfo, ui->lineEdit_motorIndex_2->text().toInt(), returnflag );

    if(1==returnflag)
    {
        QMessageBox::information(this,QStringLiteral("提示"),QStringLiteral("单轴校零成功"));
    }
    else
    {
        QMessageBox::information(this,QStringLiteral("提示"),QStringLiteral("单轴校零失败"));
    }
}

void MainWindow::on_pushButton_gohome_clicked()
{
    if( !p_powerManger )
        return;

    int returnflag=0;
    p_powerManger->returnZeroPoint( userInfo, returnflag );
}

//void MainWindow::on_pushButton_test1_clicked()
//{
//    if( !p_powerManger )
//        return;

//    RobotEngine* rob = p_powerManger->robotManager->robotsMap.value( 1, NULL );
//    if(rob!=NULL)
//    {
//        if(  rob->threadMotionEngine->mcControllerInterpreter )
//        {
//            //r
//            QVector<float> raData  ;
//            raData.resize( 4 );
//            raData[0]=1;
//            raData[1]=2;
//            raData[2]=3;
//            raData[3]=4;
//        }
//    }

//}

void MainWindow::on_spinBox_auto_speed_valueChanged(int arg1)
{
    if( !p_powerManger )
        return;

    int returnFlag;
    p_powerManger->setAutoSpeedPercent(  userInfo,  arg1,  returnFlag );

}

void MainWindow::on_comboBox_runMode_currentIndexChanged(int index)
{
    if( !p_powerManger )
        return;

    int returnFlag;
    p_powerManger->setRunModel(  userInfo,  index,  returnFlag );

}

void MainWindow::on_comboBox_moveType_currentIndexChanged(int index)
{
    if( !p_powerManger )
        return;
    int returnFlag;

    p_powerManger->setDebugModel(  userInfo,  index,  returnFlag );//1=连续
}



void MainWindow::on_checkBox_toggled(bool checked)
{
    if ( checked ){
        timer->start(500);
    }else{
        timer->stop();
    }
}

void MainWindow::on_checkBox_io_toggled(bool checked)
{
    if( !p_powerManger )
        return;


    if( checked ){
        //p_powerManger->timer.start( 10 );
    }else{
       // p_powerManger->timer.stop();
    }

//    int returnFlag;
//    RobotEngine* rob = p_powerManger->robotManager->robotsMap.value( robotId, NULL );
//    if( rob  )
//    {

//    }
}

void MainWindow::on_pushButton_clicked()
{
    int returnFlag;
    p_powerManger->setBrake(userInfo, 1, returnFlag);
}

void MainWindow::on_pushButton_2_clicked()
{
    int returnFlag;
    p_powerManger->setBrake(userInfo, 0, returnFlag);
}

void MainWindow::on_pushButton_3_clicked()
{
    vrepForm->setGeometry(800,20,300,300);
    vrepForm->show();
}

void MainWindow::on_pushButton_4_clicked()
{
    ecatForm->setGeometry(700,30,650,600);
    ecatForm->show();
}

void MainWindow::on_pushButton_5_clicked()
{
//    motionForm->setGeometry(750,40,500,500);
//    motionForm->show();
    p_powerManger->showMotionForm(robotId);
}



void MainWindow::on_pushButton_6_clicked()
{
//    motionForm->showWaveForm();
    p_powerManger->showMotionForm(robotId);
}

void MainWindow::on_comboBox_axis_2_currentIndexChanged(int index)
{
    int returnFlag;
    p_powerManger->setJogCoordinator(userInfo,index,returnFlag);
}

void MainWindow::on_checkBox_on_off_clicked()
{

}

void MainWindow::on_pushButton_7_clicked()
{
    //PL CLEAR
    int returnFlag;
    p_powerManger->clearAllPlRegister(userInfo,returnFlag);
}

void MainWindow::on_pushButton_8_clicked()
{
    //Pr CLEAR
    int returnFlag;
    p_powerManger->clearAllPrRegister(userInfo,returnFlag);
}

void MainWindow::on_pushButton_9_clicked()
{
    //R CLEAR
    int returnFlag;
    p_powerManger->clearAllLocalRegister(userInfo,returnFlag);
}

void MainWindow::on_pushButton_10_clicked()
{
    //Timer CLEAR
    int returnFlag;
    p_powerManger->clearAllTimerRegister(userInfo,returnFlag);
}

void MainWindow::on_pushButton_12_clicked()
{
    //shut down
    QMessageBox::StandardButton rb = QMessageBox::information(NULL, "Title", "关机", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

    if(rb == QMessageBox::Yes)
    {
        int returnFlag;
        p_powerManger->controllerShutDown(userInfo,returnFlag);

    }

}

void MainWindow::on_pushButton_13_clicked()
{
    //reboot
    QMessageBox::StandardButton rb = QMessageBox::information(NULL, "Title", "重启", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

    if(rb == QMessageBox::Yes)
    {
        int returnFlag;
        p_powerManger->controllerShutDownAndReboot(userInfo,returnFlag);

    }
}

void MainWindow::on_pushButton_14_clicked()
{
    filebackDlg->show();
}

void MainWindow::on_pushButton_read_sdo_clicked()
{
    int sdoMethod=ui->comboBox_sdoMethod->currentIndex();
    bool isOk;
    int rObIndex=ui->lineEdit_mainIndex->text().toInt(&isOk,16);
    int rObSubIndex=ui->lineEdit_subIndex->text().toInt(&isOk,16);
    LONG64 rData=-1;
    int rDataLen=4;
    int motorIndex=ui->lineEdit_motorIndex->text().toInt();
    if(0==sdoMethod)
    {
            rDataLen=p_powerManger->getSdo(userInfo,robotId,motorIndex,rObIndex,rObSubIndex,rData);
    }
    else if(1==sdoMethod)
    {
            rDataLen=p_powerManger->getSdoByNodeId(userInfo,motorIndex,rObIndex,rObSubIndex,rData);
    }
    else if(2==sdoMethod)
    {
            rDataLen=p_powerManger->getSdoByAlias(userInfo,motorIndex,rObIndex,rObSubIndex,rData);
    }

    if(0==rDataLen)
    {
        ui->lineEdit_length->setText(QString::number(rDataLen));
        QString tmp;
        tmp.clear();
        tmp.sprintf("%02x",rData);
        ui->lineEdit_value->setText(tmp);
       QMessageBox::information(NULL, "read sdo success成功!", "成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "read sdo failed 失败!", "失败", QMessageBox::Yes );
    }

}

void MainWindow::on_pushButton_write_sdo_clicked()
{
    int sdoMethod=ui->comboBox_sdoMethod->currentIndex();
    bool isOk;
    int rObIndex=ui->lineEdit_mainIndex->text().toInt(&isOk,16);
    int rObSubIndex=ui->lineEdit_subIndex->text().toInt(&isOk,16);
    LONG64 rData=ui->lineEdit_value->text().toLongLong(&isOk,16);
    int rDataLen=ui->lineEdit_length->text().toInt();
    int motorIndex=ui->lineEdit_motorIndex->text().toInt();
    int returnKey;
    int isSucess;
    if(0==sdoMethod)
    {
        isSucess=p_powerManger->setSdo(userInfo,robotId,motorIndex
                                       ,rObIndex,rObSubIndex,rData,rDataLen,returnKey);
    }
    else if(1==sdoMethod)
    {
        isSucess=p_powerManger->setSdoByNodeId(userInfo,motorIndex
                                       ,rObIndex,rObSubIndex,rData,rDataLen,returnKey);
    }
    else if(2==sdoMethod)
    {
        isSucess=p_powerManger->setSdoByAlias(userInfo,motorIndex
                                       ,rObIndex,rObSubIndex,rData,rDataLen,returnKey);
    }
    if(0==isSucess)
    {
       QMessageBox::information(NULL, "write sdo success成功!", "成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "writesdo failed 失败!", "失败", QMessageBox::Yes );
    }
}

void MainWindow::on_pushButton_clearBatteryError_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否清除机器人所有电池错误！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }

    bool tmpReturn;

    tmpReturn=robCtl->clearMotorBatteryError(robotId);


    if(true==tmpReturn)
    {
       QMessageBox::information(NULL, "清除机器人所有电机电池错误成功!", "成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "清除机器人所有电机电池错误失败!", "失败", QMessageBox::Yes );
    }
}




//void MainWindow::on_pushButton_run_manual_clicked()
//{

//}

//void MainWindow::on_pushButton_reduce_clicked()
//{

//}

void MainWindow::on_pushButton_enable_shutdown_clicked()
{
    int returnKey;
    p_powerManger->controlShutDownEnable(userInfo,true,returnKey);
}

void MainWindow::on_pushButton_disable_shutdown_clicked()
{
    int returnKey;
    p_powerManger->controlShutDownEnable(userInfo,false,returnKey);
}

void MainWindow::on_pushButton_moveZeroPoint_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "moveZeroPoint"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    int returnFlag;
    p_powerManger-> returnZeroPoint(userInfo ,returnFlag  );
}


void MainWindow::on_pushButton_writeAlias_clicked()
{
    int nodeId =ui->lineEdit_nodeId->text().toInt();
    unsigned short alias=ui->lineEdit_alias->text().toInt();
    int returnFlag;
    p_powerManger->setEthercatDeviceAlias(userInfo,nodeId,alias,returnFlag);
    QMessageBox::information(NULL, "setAlias", "setAlias success", QMessageBox::Yes );
}

void MainWindow::on_pushButton_getSlavesInfo_clicked()
{
    std::vector<EcatBusDevInfo_gsoap> slavesInfo;
    p_powerManger->getEthercatSlavesInformation(userInfo,slavesInfo);

    model_ethercatSlavesInfo->clear();
    //定义item
    QStandardItem* item = 0;
    int lineSize=14;

    for(int i=0;i<slavesInfo.size();i++)
    {
        item = new QStandardItem("node id");
        model_ethercatSlavesInfo->setItem(lineSize*i+0,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].node));
        model_ethercatSlavesInfo->setItem(lineSize*i+0,1,item);

        item = new QStandardItem("alias");
        model_ethercatSlavesInfo->setItem(lineSize*i+1,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].alias));
        model_ethercatSlavesInfo->setItem(lineSize*i+1,1,item);

        item = new QStandardItem("vendorId");
        model_ethercatSlavesInfo->setItem(lineSize*i+2,0,item);
        //8代表宽度，16表示16进制，空位补零
        item = new QStandardItem(QString("0x%1").arg(slavesInfo[i].vendorId, 8, 16, QLatin1Char('0')));
        model_ethercatSlavesInfo->setItem(lineSize*i+2,1,item);


        item = new QStandardItem("productCode");
        model_ethercatSlavesInfo->setItem(lineSize*i+3,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].productCode));
        model_ethercatSlavesInfo->setItem(lineSize*i+3,1,item);

        item = new QStandardItem("revisionNumber");
        model_ethercatSlavesInfo->setItem(lineSize*i+4,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].revisionNumber));
        model_ethercatSlavesInfo->setItem(lineSize*i+4,1,item);

        item = new QStandardItem("serial_number");
        model_ethercatSlavesInfo->setItem(lineSize*i+5,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].serial_number));
        model_ethercatSlavesInfo->setItem(lineSize*i+5,1,item);

        item = new QStandardItem("al_state");
        model_ethercatSlavesInfo->setItem(lineSize*i+6,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].al_state));
        model_ethercatSlavesInfo->setItem(lineSize*i+6,1,item);

        item = new QStandardItem("error_flag");
        model_ethercatSlavesInfo->setItem(lineSize*i+7,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].error_flag));
        model_ethercatSlavesInfo->setItem(lineSize*i+7,1,item);

        item = new QStandardItem("sync_count");
        model_ethercatSlavesInfo->setItem(lineSize*i+8,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].sync_count));
        model_ethercatSlavesInfo->setItem(lineSize*i+8,1,item);

        item = new QStandardItem("sdo_count");
        model_ethercatSlavesInfo->setItem(lineSize*i+9,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].sdo_count));
        model_ethercatSlavesInfo->setItem(lineSize*i+9,1,item);

        item = new QStandardItem("devType");
        model_ethercatSlavesInfo->setItem(lineSize*i+10,0,item);
        item = new QStandardItem(QString("%1").arg(slavesInfo[i].devType));
        model_ethercatSlavesInfo->setItem(lineSize*i+10,1,item);

        item = new QStandardItem("devName");
        model_ethercatSlavesInfo->setItem(lineSize*i+11,0,item);
        item = new QStandardItem(QString::fromStdString(slavesInfo[i].devName));
        model_ethercatSlavesInfo->setItem(lineSize*i+11,1,item);

        item = new QStandardItem("mappingObjectFile");
        model_ethercatSlavesInfo->setItem(lineSize*i+12,0,item);
        item = new QStandardItem(QString::fromStdString(slavesInfo[i].mappingObjectFile));
        model_ethercatSlavesInfo->setItem(lineSize*i+12,1,item);
    }


    ui->tableView_ethercatSlavesInfo->setModel(model_ethercatSlavesInfo);
    ui->tableView_ethercatSlavesInfo->resizeColumnToContents(0);
    ui->tableView_ethercatSlavesInfo->resizeColumnToContents(1);
    ui->tableView_ethercatSlavesInfo->resizeColumnToContents(2);
    ui->tableView_ethercatSlavesInfo->show();
    QMessageBox::information(NULL, "getSlavesInfo", "getSlavesInfo success", QMessageBox::Yes );
}

void MainWindow::on_checkBox_enableNoCalibrateJog_clicked()
{
    int returnFlag;
     p_powerManger->allowSingleAxisJog(userInfo,ui->checkBox_enableNoCalibrateJog->isChecked(),returnFlag);
}

void MainWindow::on_pushButton_getCalibrateInfo_clicked()
{
    S_AXISGROUP_ZERO_INFORMATION zeroInformationOut;
    p_powerManger->getCalibrateInformation(userInfo,zeroInformationOut );

    model_axisgroupCalibrateInfo->clear();
    //定义item
    QStandardItem* item = 0;
    int lineSize=4;

    QString magementState;
    if(0==zeroInformationOut.state)
    {
        magementState="初始化中";
    }
    else if(1==zeroInformationOut.state)
    {
        magementState="正常";
    }
    else if(2==zeroInformationOut.state)
    {
        magementState="MD5校验错误";
    }
    else if(3==zeroInformationOut.state)
    {
        magementState="零点文件信息不全";
    }
    item = new QStandardItem("零点管理模块状态");
    model_axisgroupCalibrateInfo->setItem(0,0,item);
    item = new QStandardItem(magementState);
    model_axisgroupCalibrateInfo->setItem(0,1,item);

    for(int i=0;i<zeroInformationOut.axisZeroState.size();i++)
    {
        QString axisZeroState;
        if(0==zeroInformationOut.axisZeroState[i])
        {
            axisZeroState="未校准";
        }
        else if(1==zeroInformationOut.axisZeroState[i])
        {
            axisZeroState="已校准";
        }
        else if(2==zeroInformationOut.axisZeroState[i])
        {
            axisZeroState="掉电无零点";
        }
        else if(3==zeroInformationOut.axisZeroState[i])
        {
            axisZeroState="文件校验错误";
        }
        item = new QStandardItem(QString("%1轴零点状态").arg(i+1));
        model_axisgroupCalibrateInfo->setItem(lineSize*i+2,0,item);
        item = new QStandardItem(axisZeroState);
        model_axisgroupCalibrateInfo->setItem(lineSize*i+2,1,item);

        item = new QStandardItem(QString("%1轴绝对零点编码器值").arg(i+1));
        model_axisgroupCalibrateInfo->setItem(lineSize*i+3,0,item);
        item = new QStandardItem(QString("%1").arg(zeroInformationOut.absoluteZeroMotorValue[i]));
        model_axisgroupCalibrateInfo->setItem(lineSize*i+3,1,item);

        item = new QStandardItem(QString("%1轴机械零点偏移值").arg(i+1));
        model_axisgroupCalibrateInfo->setItem(lineSize*i+4,0,item);
        item = new QStandardItem(QString::number(zeroInformationOut.jointMechanicalZeroValue[i],'f',3));
        model_axisgroupCalibrateInfo->setItem(lineSize*i+4,1,item);


    }


    ui->tableView_axisgroupCalibrateInfo->setModel(model_axisgroupCalibrateInfo);
    ui->tableView_axisgroupCalibrateInfo->resizeColumnToContents(0);
    ui->tableView_axisgroupCalibrateInfo->resizeColumnToContents(1);
    ui->tableView_axisgroupCalibrateInfo->resizeColumnToContents(2);
    ui->tableView_axisgroupCalibrateInfo->show();
    QMessageBox::information(NULL, "getCalibrateInfo", "getCalibrateInfo success", QMessageBox::Yes );

}

void MainWindow::on_pushButton_run_all_clicked()
{
    if( !p_powerManger )
        return;
    QMessageBox message(QMessageBox::Question, "提示", "当前机器人程序启动执行"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    int returnFlag;
//    p_powerManger->programAllRun(userInfo,returnFlag);
    p_powerManger->programRun(userInfo,returnFlag);

}

void MainWindow::on_pushButton_cease_all_clicked()
{
    if( !p_powerManger )
        return;
    int returnFlag;
//    p_powerManger->programAllCease(userInfo,returnFlag);
    p_powerManger->programCease(userInfo,returnFlag);
}

void MainWindow::on_pushButton_stop_all_clicked()
{
    if( !p_powerManger )
        return;
    int returnFlag;
//    p_powerManger->programAllReset(userInfo,returnFlag);
    p_powerManger->programReset(userInfo,returnFlag);
}

void MainWindow::on_pushButton_setAllT1_clicked()
{
    if( !p_powerManger )
        return;
    int returnFlag;
    p_powerManger->setAllRunModel(userInfo,ENUM_CONTROL_T1,returnFlag);
}

void MainWindow::on_pushButton_setAllAuto_clicked()
{
    if( !p_powerManger )
        return;
    int returnFlag;
    p_powerManger->setAllRunModel(userInfo,ENUM_CONTROL_AUTO,returnFlag);
}

void MainWindow::on_comboBox_robotId_currentIndexChanged(int index)
{
    if( !p_powerManger )
        return;
    int returnFlag;
    p_powerManger->changeCurrentRobotId(userInfo,index+1,returnFlag);
//    UpdateDataLv1 tmpUpdateDataLv1;
//    p_powerManger->updateControllerInfoLevel1(userInfo,index+1,tmpUpdateDataLv1);
}

void MainWindow::on_pushButton_read_sdo_2_clicked()
{
    //set torque
    robCtl->setMotorTorqueLimit(robotId,ui->lineEdit_motorIndex_torque->text().toInt(),
                               ui->lineEdit_maxTorquePos->text().toInt(),
                               ui->lineEdit_maxTorqueNeg->text().toInt());
    QMessageBox::information(NULL, "setMaxTorque", "setMaxTorque success", QMessageBox::Yes );

}

void MainWindow::on_pushButton_setTorqueFilter_clicked()
{
    //set torque filter
    robCtl->setMotorTorqueFilterTime(robotId,ui->lineEdit_motorIndex_torque->text().toInt(),
                               ui->lineEdit_torqueFilter->text().toInt());
    QMessageBox::information(NULL, "setMaxTorque", "setMaxTorque success", QMessageBox::Yes );
}

void MainWindow::on_pushButton_goZeroRobot_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否startGoZero_forUser！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    p_powerManger->startGoZero_forUser(robotId);
}

void MainWindow::on_pushButton_goZeroOneRobot_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否startGoZero_forUser！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    p_powerManger->startGoZero_forUser(robotId,ui->lineEdit_motorIndex_2->text().toInt());
}

void MainWindow::on_pushButton_ceaseReturingZero_clicked()
{
    p_powerManger->haltGoZero_forUser(robotId);
    QMessageBox::information(NULL, "cease goZero ", "cease goZero", QMessageBox::Yes );
}

void MainWindow::on_pushButton_agvTest_clicked()
{
    int returnFlag;
    p_powerManger->setReplanCoutLimitWhenFailure(userInfo,ui->lineEdit_agvTest->text().toInt(),
                                                 returnFlag);
}




void MainWindow::on_pushButton_addVitrualBlock_clicked()
{

}

void MainWindow::on_pushButton_deleteVitrualBlock_clicked()
{

}




void MainWindow::on_pushButton_loadMap_2_clicked()
{
    int returnFlag;
    QString filePath =ui->lineEdit_mapPath->text();
   int first = filePath.lastIndexOf ("/"); //从后面查找"/"位置
   QString title = filePath.right (filePath.length ()-first-1); //从右边截取
   qDebug()<<title;
    p_powerManger->loadMap(userInfo,title.toStdString(),returnFlag);
}

void MainWindow::on_pushButton_browseFile_clicked()
{
    //定义文件对话框类
       QFileDialog *fileDialog = new QFileDialog(this);
       fileDialog->resize(400,500);
       //定义文件对话框标题
       fileDialog->setWindowTitle(tr("选择文件"));
       //设置默认文件路径
       fileDialog->setDirectory(D_MAP_PATH);
       //设置文件过滤器
       fileDialog->setNameFilter(tr("yaml(*.yaml)"));
       //设置可以选择多个文件,默认为只能选择一个文件QFileDialog::ExistingFiles
       fileDialog->setFileMode(QFileDialog::ExistingFiles);
       //设置视图模式
       fileDialog->setViewMode(QFileDialog::Detail);
       //打印所有选择的文件的路径
       QStringList fileNames;
       if(fileDialog->exec())
       {
           fileNames = fileDialog->selectedFiles();
       }
        qDebug()<<fileNames;
        if(fileNames.size()>0)
        {
            ui->lineEdit_mapPath->setText(fileNames[0]);
        }
}

void MainWindow::on_pushButton_createMapStart_clicked()
{
    int returnFlag;
    p_powerManger->createMapStart(userInfo,returnFlag);
}

void MainWindow::on_pushButton_createMapStop_clicked()
{
    int returnFlag;
    QString tmpFilePath;
    tmpFilePath+=ui->lineEdit_mapName_2->text();

    p_powerManger->createMapEnd(userInfo,tmpFilePath.toStdString(),  returnFlag);
}

void MainWindow::on_pushButton_setMapSolver_clicked()
{
    int returnFlag;
    p_powerManger->setMapSolver(userInfo,(E_MAP_SOLVER)ui->lineEdit_mapSolver->text().toInt(),1, returnFlag);
}

void MainWindow::on_pushButton_setOdomSolver_clicked()
{
    int returnFlag;
    p_powerManger->setOdomSolver(userInfo,(E_ODOM_SOLVER)ui->lineEdit_odometer->text().toInt(), returnFlag);
}

void MainWindow::on_pushButton_setLocationSolver_clicked()
{
    int returnFlag;
    p_powerManger->setLocationSolver(userInfo,(E_LOCATION_SOLVER)ui->lineEdit_locationSolver->text().toInt(), returnFlag);
}

void MainWindow::on_pushButton_getVehiclePosition_clicked()
{

    VehiclePosition positionReturn;
    p_powerManger->getVehiclePosition(userInfo,positionReturn);
    ui->lineEdit_rx->setText(QString::number(positionReturn.x));
    ui->lineEdit_ry->setText(QString::number(positionReturn.y));
    ui->lineEdit_ra->setText(QString::number(positionReturn.rotate));
}

void MainWindow::on_pushButton_setVehiclePosition_clicked()
{
    int returnFlag;
    VehiclePosition positionIn;
    positionIn.x=ui->lineEdit_ix->text().toDouble();
    positionIn.y=ui->lineEdit_iy->text().toDouble();
    positionIn.rotate=ui->lineEdit_ia->text().toDouble();
    p_powerManger->setVehiclePosition(userInfo,positionIn, returnFlag);

}

void MainWindow::on_pushButton_setTrajectoryGlobalPlanSolver_clicked()
{
    int returnFlag;
    p_powerManger->setTrajectoryGlobalPlanSolver(userInfo,(E_TRAJECTORY_GLOBAL_SOLVER)ui->lineEdit_globalPlan->text().toInt(), returnFlag);
}

void MainWindow::on_pushButton_setTrajectoryLocalPlanSolver_clicked()
{
    int returnFlag;
    p_powerManger->setTrajectoryLocalPlanSolver(userInfo,(E_TRAJECTORY_LOCAL_SOLVER)ui->lineEdit_localPlan->text().toInt(), returnFlag);
}

void MainWindow::on_pushButton_moveToPosition_2_clicked()
{
    int returnFlag;
    VehiclePosition positionIn;
    positionIn.x=ui->lineEdit_tx->text().toDouble();
    positionIn.y=ui->lineEdit_ty->text().toDouble();
    positionIn.rotate=ui->lineEdit_ta->text().toDouble();
    p_powerManger->moveToPosition(userInfo,positionIn, ui->lineEdit_velocity_2->text().toDouble(),returnFlag);
}

void MainWindow::on_pushButton_changeVelocity_2_clicked()
{
    int returnFlag;

    p_powerManger->changeVelocity(userInfo,ui->lineEdit_velocity_2->text().toDouble(),returnFlag);
}

void MainWindow::on_pushButton_start_clicked()
{
    int returnFlag;

    p_powerManger->startMotion(userInfo,returnFlag);
}

void MainWindow::on_pushButton_cease_clicked()
{
    int returnFlag;

    p_powerManger->ceaseMotion(userInfo,returnFlag);
}

void MainWindow::on_pushButton_stop_3_clicked()
{
    int returnFlag;

    p_powerManger->cancelMotion(userInfo,returnFlag);
}


void MainWindow::on_pushButton_15_clicked()
{
    int returnFlag;
    p_powerManger->resetMaster(userInfo,returnFlag);
}



void MainWindow::on_pushButton_forceQuit_clicked()
{
    p_powerManger->forceQuitProgram();
}

void MainWindow::on_pushButton_ultrasonicPowerNoise_clicked()
{
     p_powerManger->setUltrasonicPowerSupplyNoiseClass(ui->comboBox_powerSupplyNoiseClass->currentIndex());
}

void MainWindow::on_pushButton_browser_program_files_clicked()
{
    //定义文件对话框类
       QFileDialog *fileDialog = new QFileDialog(this);
       fileDialog->resize(400,500);
       //定义文件对话框标题
       fileDialog->setWindowTitle(tr("选择文件"));
       //设置默认文件路径
       QString tmpFilePath=D_TCRCONTROLLER_DATA_PATH;
       QString configFile = tmpFilePath+ROBOT_COMMON_NAME+QString::number( robotId )+"/program/";
       fileDialog->setDirectory(configFile);
       //设置文件过滤器
       fileDialog->setNameFilter(tr("txt(*.txt)"));
       //设置可以选择多个文件,默认为只能选择一个文件QFileDialog::ExistingFiles
       fileDialog->setFileMode(QFileDialog::ExistingFiles);
       //设置视图模式
       fileDialog->setViewMode(QFileDialog::Detail);
       //打印所有选择的文件的路径
       QStringList fileNames;
       if(fileDialog->exec())
       {
           fileNames = fileDialog->selectedFiles();
       }
        qDebug()<<fileNames;
        if(fileNames.size()>0)
        {

            QString filePath =fileNames[0];
           int first = filePath.lastIndexOf ("/"); //从后面查找"/"位置
           QString title = filePath.right (filePath.length ()-first-1); //从右边截取
            ui->lineEdit_filename->setText(title);
            on_pushButton_open_file_clicked();
        }
}

void MainWindow::on_pushButton_calibrate_agv_offset_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否修改agv位置标定！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    double x,y,r;
    int tmpReturn;
    x=ui->lineEdit_vehicleCalibrate_xOffset->text().toDouble();
    y=ui->lineEdit_vehicleCalibrate_yOffset->text().toDouble();
    r=ui->lineEdit_vehicleCalibrate_rOffset->text().toDouble();
    p_powerManger->calibrateVehicle(userInfo,x,y,r,tmpReturn);
    if(1==tmpReturn)
    {
        QMessageBox::information(NULL, "information", "修改成功！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "修改失败！", QMessageBox::Yes );
    }

}

void MainWindow::on_pushButton_clear_custom_odom_clicked()
{
    int tmpReturn;
    p_powerManger->resetCustomOdometer_positionManage(userInfo,tmpReturn);
}

void MainWindow::on_checkBox_ultrasonic_check_status_command_clicked(bool checked)
{
    p_powerManger->setUltrasonicSensorCheckEnable(checked);
}

void MainWindow::on_checkBox_ultrasonic_check_pointCloud_command_clicked()
{
    bool checked=ui->checkBox_ultrasonic_check_pointCloud_command->isChecked();
    p_powerManger->setPointCloudCheckEnable(checked);
}

void MainWindow::on_pushButton_resetMasterTimeMeasure_clicked()
{
    int tmpReturn;
    p_powerManger->resetMasterTimeMeasure(userInfo,tmpReturn);
<<<<<<< HEAD
}

void MainWindow::on_pushButton_vehicle_moveToPosition_clicked()
{
    int tmpReturn;
    MovingToNavagationParameter parameter;
    parameter.isDetectBarrier=ui->checkBox_vehicle_target_isDetectBarrier->isChecked();
    parameter.isPositiveDirection=ui->checkBox_vehicle_target_isPositiveMove->isChecked();
    parameter.laserTypeNum=ui->lineEdit_vehicle_laserType->text().toInt();
    parameter.vmarkTypeNum=ui->lineEdit_vehicle_vmarkType->text().toInt();
    parameter.speedRatio=ui->lineEdit_vehicle_speedRatio->text().toDouble();
    parameter.x=ui->lineEdit_vehicle_target_x->text().toDouble();
    parameter.y=ui->lineEdit_vehicle_target_y->text().toDouble();
    parameter.rotate=ui->lineEdit_vehicle_target_rotate->text().toDouble();

    p_powerManger->moveToNavgationPoint(userInfo,parameter,tmpReturn);
}

void MainWindow::on_pushButton_setDefaultMap_clicked()
{
    int returnFlag;
    QString filePath =ui->lineEdit_mapPath->text();
   int first = filePath.lastIndexOf ("/"); //从后面查找"/"位置
   QString title = filePath.right (filePath.length ()-first-1); //从右边截取
   qDebug()<<title;
    p_powerManger->setDefaultMapName(userInfo,title.toStdString(),returnFlag);
}

void MainWindow::on_pushButton_modifyFileDirAuthority_clicked()
{
    qDebug()<<"on_pushButton_modifyFileDirAuthority_clicked";
    QString systemCommand="chmod -R 777  ";
    systemCommand+=D_TCRCONTROLLER_WORK_PATH;
    systemCommand+="&";
    system(systemCommand.toLatin1().data());
    QMessageBox::information(NULL, "information", "修改文件夹权限完成！", QMessageBox::Yes );
}

void MainWindow::on_pushButton_ultrasonic_change_id_clicked()
{
    int oldId=ui->lineEdit_ultrasonic_old_id->text().toInt();
    int newId=ui->lineEdit_ultrasonic_new_id->text().toInt();
    int tmpReturn;
    int isOk=p_powerManger->setUltrasonicSensor485Address(userInfo,oldId,newId,tmpReturn);
    if(1==isOk)
    {
        QMessageBox::information(NULL, "information", "修改地址成功！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "修改地址失败！", QMessageBox::Yes );
    }
}

void MainWindow::on_pushButton_get_serialPorInfo_clicked()
{
    ui->textEdit->clear();
    QStringList infoOut;
    p_powerManger->getSerialPortListInfo(userInfo,infoOut);
    for(int i=0;i<infoOut.size();i++)
    {
        ui->textEdit->append(infoOut[i]);
    }
=======
>>>>>>> origin/master
}

void MainWindow::on_pushButton_16_clicked()
{
    int tmpFlag=ui->lineEdit_globalManagerDebugFlag->text().toInt();
    p_powerManger->setGlobalManagerDebugFlag(tmpFlag);
}

void MainWindow::on_pushButton_setMainWindowDebugFlag_clicked()
{
    int tmpFlag=ui->lineEdit_mainWindowDebugFlag->text().toInt();
    setDebugFlag(tmpFlag);
}

void MainWindow::on_pushButton_setUltrasonicSensorDebugFlag_clicked()
{
    int tmpFlag=ui->lineEdit_ultrasonicSensorDebugFlag->text().toInt();
    p_powerManger->setUltrasonicSensorDebugFlag(tmpFlag);
}

void MainWindow::on_pushButton_setNewTime_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否修改系统时间！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    int tmpFlag;
    p_powerManger->changeComputerTime(userInfo,ui->lineEdit_newTimeSet->text().toStdString(),tmpFlag);
    if(1==tmpFlag)
    {
        QMessageBox::information(NULL, "information", "修改时间成功！", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "information", "修改时间失败！", QMessageBox::Yes );
    }
}

void MainWindow::on_pushButton_clearBatteryErrorByAxis_clicked()
{
    QMessageBox message(QMessageBox::Question, "提示", "是否清除单轴电池错误！"
                        , QMessageBox::Yes|QMessageBox::No , NULL);
    if(message.exec() == QMessageBox::No)
    {
        return;
    }
    bool tmpReturn;
    int axisId=ui->lineEdit_motorIndex_2->text().toInt();

    tmpReturn=robCtl->clearMotorBatteryErrorByAxis(robotId,axisId);
    if(true==tmpReturn)
    {
       QMessageBox::information(NULL, "清除机器人电机单轴电池错误成功!", "成功", QMessageBox::Yes );
    }
    else
    {
        QMessageBox::information(NULL, "清除机器人电机单轴电池错误失败!", "失败", QMessageBox::Yes );
    }
}
